-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex02.ino
40 lines (36 loc) · 1.26 KB
/
ex02.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
36
37
38
39
40
// Arduino Engineering Lab
// Exercise n. 02
// define constants
const int led_pins[] = {9, 10, 11, 12, 13}; // array of LED pins
const int no_pins = sizeof(led_pins) / sizeof(int); // number of pins
const int between_HL = 250; // milliseconds between ON and OFF
// initialisation
void setup()
{
// set the digital pins as outputs using a for loop
for (int cnt = 0; cnt < no_pins; cnt++)
{
pinMode(led_pins[cnt], OUTPUT);
digitalWrite(led_pins[cnt], LOW);
}
}
// main loop function
void loop()
{
// turn the leds ON and OFF from first to last
for (int cnt = 0; cnt < no_pins; cnt++)
{
digitalWrite(led_pins[cnt], HIGH); // turn the LED on
delay(between_HL); // wait for a second
digitalWrite(led_pins[cnt], HIGH); // turn the LED off
delay(between_HL); // wait for a second
}
// turn the leds ON and OFF from last to first
for (int cnt = no_pins - 2; cnt >= 1; cnt--)
{
digitalWrite(led_pins[cnt], HIGH); // turn the LED on
delay(between_HL); // wait for a second
digitalWrite(led_pins[cnt], HIGH); // turn the LED off
delay(between_HL); // wait for a second
}
}