Advertisement
microrobotics

Bar Graph LED 10 Segments

Apr 17th, 2023
712
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. This code provides a basic framework for driving a Bar Graph LED 10 Segment using an Arduino. You can modify the code to suit your specific requirements, such as changing the delay time or adding additional LEDs.
  7. */
  8.  
  9.  
  10. // define the LED pins
  11. const int LED_1 = 2;
  12. const int LED_2 = 3;
  13. const int LED_3 = 4;
  14. const int LED_4 = 5;
  15. const int LED_5 = 6;
  16. const int LED_6 = 7;
  17. const int LED_7 = 8;
  18. const int LED_8 = 9;
  19. const int LED_9 = 10;
  20. const int LED_10 = 11;
  21.  
  22. // define the delay time
  23. const int DELAY_TIME = 100;
  24.  
  25. void setup() {
  26.   // set the LED pins as outputs
  27.   pinMode(LED_1, OUTPUT);
  28.   pinMode(LED_2, OUTPUT);
  29.   pinMode(LED_3, OUTPUT);
  30.   pinMode(LED_4, OUTPUT);
  31.   pinMode(LED_5, OUTPUT);
  32.   pinMode(LED_6, OUTPUT);
  33.   pinMode(LED_7, OUTPUT);
  34.   pinMode(LED_8, OUTPUT);
  35.   pinMode(LED_9, OUTPUT);
  36.   pinMode(LED_10, OUTPUT);
  37.  
  38.   // initialize the serial port for debugging
  39.   Serial.begin(9600);
  40.  
  41.   // print a message to the serial port
  42.   Serial.println("Bar Graph LED ready!");
  43. }
  44.  
  45. void loop() {
  46.   // turn on the first LED
  47.   digitalWrite(LED_1, HIGH);
  48.   delay(DELAY_TIME);
  49.  
  50.   // turn on the second LED
  51.   digitalWrite(LED_2, HIGH);
  52.   delay(DELAY_TIME);
  53.  
  54.   // turn on the third LED
  55.   digitalWrite(LED_3, HIGH);
  56.   delay(DELAY_TIME);
  57.  
  58.   // turn on the fourth LED
  59.   digitalWrite(LED_4, HIGH);
  60.   delay(DELAY_TIME);
  61.  
  62.   // turn on the fifth LED
  63.   digitalWrite(LED_5, HIGH);
  64.   delay(DELAY_TIME);
  65.  
  66.   // turn on the sixth LED
  67.   digitalWrite(LED_6, HIGH);
  68.   delay(DELAY_TIME);
  69.  
  70.   // turn on the seventh LED
  71.   digitalWrite(LED_7, HIGH);
  72.   delay(DELAY_TIME);
  73.  
  74.   // turn on the eighth LED
  75.   digitalWrite(LED_8, HIGH);
  76.   delay(DELAY_TIME);
  77.  
  78.   // turn on the ninth LED
  79.   digitalWrite(LED_9, HIGH);
  80.   delay(DELAY_TIME);
  81.  
  82.   // turn on the tenth LED
  83.   digitalWrite(LED_10, HIGH);
  84.   delay(DELAY_TIME);
  85.  
  86.   // turn off all LEDs
  87.   digitalWrite(LED_1, LOW);
  88.   digitalWrite(LED_2, LOW);
  89.   digitalWrite(LED_3, LOW);
  90.   digitalWrite(LED_4, LOW);
  91.   digitalWrite(LED_5, LOW);
  92.   digitalWrite(LED_6, LOW);
  93.   digitalWrite(LED_7, LOW);
  94.   digitalWrite(LED_8, LOW);
  95.   digitalWrite(LED_9, LOW);
  96.   digitalWrite(LED_10, LOW);
  97.   delay(DELAY_TIME);
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement