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 segment is turned on in sequence using the digitalWrite() function with a delay between each segment.
- After all segments are turned on, they are turned off in sequence with the same delay using digitalWrite(). This sequence repeats indefinitely.
- 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.
- */
- // define the LED pins
- const int LED_A = 2;
- const int LED_B = 3;
- const int LED_C = 4;
- const int LED_D = 5;
- const int LED_E = 6;
- const int LED_F = 7;
- const int LED_G = 8;
- const int LED_DP = 9;
- // define the delay time
- const int DELAY_TIME = 100;
- void setup() {
- // set the LED pins as outputs
- pinMode(LED_A, OUTPUT);
- pinMode(LED_B, OUTPUT);
- pinMode(LED_C, OUTPUT);
- pinMode(LED_D, OUTPUT);
- pinMode(LED_E, OUTPUT);
- pinMode(LED_F, OUTPUT);
- pinMode(LED_G, OUTPUT);
- pinMode(LED_DP, 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 segment A
- digitalWrite(LED_A, HIGH);
- delay(DELAY_TIME);
- // turn on segment B
- digitalWrite(LED_B, HIGH);
- delay(DELAY_TIME);
- // turn on segment C
- digitalWrite(LED_C, HIGH);
- delay(DELAY_TIME);
- // turn on segment D
- digitalWrite(LED_D, HIGH);
- delay(DELAY_TIME);
- // turn on segment E
- digitalWrite(LED_E, HIGH);
- delay(DELAY_TIME);
- // turn on segment F
- digitalWrite(LED_F, HIGH);
- delay(DELAY_TIME);
- // turn on segment G
- digitalWrite(LED_G, HIGH);
- delay(DELAY_TIME);
- // turn on the decimal point
- digitalWrite(LED_DP, HIGH);
- delay(DELAY_TIME);
- // turn off all segments
- digitalWrite(LED_A, LOW);
- digitalWrite(LED_B, LOW);
- digitalWrite(LED_C, LOW);
- digitalWrite(LED_D, LOW);
- digitalWrite(LED_E, LOW);
- digitalWrite(LED_F, LOW);
- digitalWrite(LED_G, LOW);
- digitalWrite(LED_DP, LOW);
- delay(DELAY_TIME);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement