-
Notifications
You must be signed in to change notification settings - Fork 0
/
LED_Light_Bar.ino
35 lines (35 loc) · 950 Bytes
/
LED_Light_Bar.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Used with kind permission from
// Warwick A Smith, startingelectronics.com
// Knight rider display on 8 LEDs
void setup()
{
for (int i = 2; i < 10; i++)
{ // Choose pins 2-9
pinMode(i, OUTPUT); // Set the pins as outputs
}
}
// Define function to turn off all LEDs at the same time
void allLEDsOff(void)
{
for (int i = 2; i < 10; i++)
{
digitalWrite(i, LOW);
}
}
// Switch on LEDs in sequence from left to right
void loop()
{
for (int i = 2; i < 9; i++)
{ // Run loop once for each LED
allLEDsOff(); // Turn off all LEDs
digitalWrite(i, HIGH); // Turn on current LED
delay(200); // Delay of 200 ms,
// then repeat loop to move on to next LED
}
for (int i = 9; i > 2; i--)
{ // Light LEDs from right to left
allLEDsOff();
digitalWrite(i, HIGH);
delay(200);
}
}