Advertisement
microrobotics

5-segment Bar Graph LED

Apr 17th, 2023
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. This code sets the LED pins as outputs using the pinMode() function in the setup() function. In the loop() function, each LED is turned on in sequence using the digitalWrite() function with a delay between each LED.
  3.  
  4. After all LEDs are turned on, they are turned off in sequence with the same delay using digitalWrite(). This sequence repeats indefinitely.
  5.  
  6. Note that the specific pinout and segment mapping may vary depending on the manufacturer of your Bar Graph LED. You should refer to the datasheet or product documentation for the correct pinout and segment mapping for your device.
  7. */
  8.  
  9. // define the LED pins
  10. const int LED_1 = 2;
  11. const int LED_2 = 3;
  12. const int LED_3 = 4;
  13. const int LED_4 = 5;
  14. const int LED_5 = 6;
  15.  
  16. // define the delay time
  17. const int DELAY_TIME = 100;
  18.  
  19. void setup() {
  20.   // set the LED pins as outputs
  21.   pinMode(LED_1, OUTPUT);
  22.   pinMode(LED_2, OUTPUT);
  23.   pinMode(LED_3, OUTPUT);
  24.   pinMode(LED_4, OUTPUT);
  25.   pinMode(LED_5, OUTPUT);
  26.  
  27.   // initialize the serial port for debugging
  28.   Serial.begin(9600);
  29.  
  30.   // print a message to the serial port
  31.   Serial.println("Bar Graph LED ready!");
  32. }
  33.  
  34. void loop() {
  35.   // turn on the first LED
  36.   digitalWrite(LED_1, HIGH);
  37.   delay(DELAY_TIME);
  38.  
  39.   // turn on the second LED
  40.   digitalWrite(LED_2, HIGH);
  41.   delay(DELAY_TIME);
  42.  
  43.   // turn on the third LED
  44.   digitalWrite(LED_3, HIGH);
  45.   delay(DELAY_TIME);
  46.  
  47.   // turn on the fourth LED
  48.   digitalWrite(LED_4, HIGH);
  49.   delay(DELAY_TIME);
  50.  
  51.   // turn on the fifth LED
  52.   digitalWrite(LED_5, HIGH);
  53.   delay(DELAY_TIME);
  54.  
  55.   // turn off all LEDs
  56.   digitalWrite(LED_1, LOW);
  57.   digitalWrite(LED_2, LOW);
  58.   digitalWrite(LED_3, LOW);
  59.   digitalWrite(LED_4, LOW);
  60.   digitalWrite(LED_5, LOW);
  61.   delay(DELAY_TIME);
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement