Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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.
- After all LEDs are turned on, they are turned off in sequence with the same delay using digitalWrite(). This sequence repeats indefinitely.
- 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.
- */
- // define the LED pins
- const int LED_1 = 2;
- const int LED_2 = 3;
- const int LED_3 = 4;
- const int LED_4 = 5;
- const int LED_5 = 6;
- const int LED_6 = 7;
- const int LED_7 = 8;
- const int LED_8 = 9;
- const int LED_9 = 10;
- const int LED_10 = 11;
- // define the delay time
- const int DELAY_TIME = 100;
- void setup() {
- // set the LED pins as outputs
- pinMode(LED_1, OUTPUT);
- pinMode(LED_2, OUTPUT);
- pinMode(LED_3, OUTPUT);
- pinMode(LED_4, OUTPUT);
- pinMode(LED_5, OUTPUT);
- pinMode(LED_6, OUTPUT);
- pinMode(LED_7, OUTPUT);
- pinMode(LED_8, OUTPUT);
- pinMode(LED_9, OUTPUT);
- pinMode(LED_10, OUTPUT);
- // initialize the serial port for debugging
- Serial.begin(9600);
- // print a message to the serial port
- Serial.println("Bar Graph LED ready!");
- }
- void loop() {
- // turn on the first LED
- digitalWrite(LED_1, HIGH);
- delay(DELAY_TIME);
- // turn on the second LED
- digitalWrite(LED_2, HIGH);
- delay(DELAY_TIME);
- // turn on the third LED
- digitalWrite(LED_3, HIGH);
- delay(DELAY_TIME);
- // turn on the fourth LED
- digitalWrite(LED_4, HIGH);
- delay(DELAY_TIME);
- // turn on the fifth LED
- digitalWrite(LED_5, HIGH);
- delay(DELAY_TIME);
- // turn on the sixth LED
- digitalWrite(LED_6, HIGH);
- delay(DELAY_TIME);
- // turn on the seventh LED
- digitalWrite(LED_7, HIGH);
- delay(DELAY_TIME);
- // turn on the eighth LED
- digitalWrite(LED_8, HIGH);
- delay(DELAY_TIME);
- // turn on the ninth LED
- digitalWrite(LED_9, HIGH);
- delay(DELAY_TIME);
- // turn on the tenth LED
- digitalWrite(LED_10, HIGH);
- delay(DELAY_TIME);
- // turn off all LEDs
- digitalWrite(LED_1, LOW);
- digitalWrite(LED_2, LOW);
- digitalWrite(LED_3, LOW);
- digitalWrite(LED_4, LOW);
- digitalWrite(LED_5, LOW);
- digitalWrite(LED_6, LOW);
- digitalWrite(LED_7, LOW);
- digitalWrite(LED_8, LOW);
- digitalWrite(LED_9, LOW);
- digitalWrite(LED_10, LOW);
- delay(DELAY_TIME);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement