1 /* Arduino Projects for Dummies
4 * Chapter 4: The All-Seeing Eye
5 * Sequentially lights up a series of LEDs
10 // A variable to set a delay time between each LED
13 // A variable to store which LED we are currently working on
16 // A variable to store the direction of travel of LEDs
19 // A variable to store the last time we changed something
20 unsigned long timeChanged = 0;
22 // Create an array to hold the value for each LED pin
23 byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
26 // Set all pins for OUTPUT
27 for (int x=0; x<10; x++) {
28 pinMode(ledPin[x], OUTPUT);
32 timeChanged = millis();
36 // Check whether it has been long enough
37 if ((millis() - timeChanged) > timeDelay) {
39 // Turn off all of the LEDs
40 for (int x=0; x<10; x++) {
41 digitalWrite(ledPin[x], LOW);
44 // Turn on the current LED
45 digitalWrite(ledPin[currentLED], HIGH);
47 // Increment by the direction value
50 // If we are at the end of a row, change direction
51 if (currentLED == 9) {
54 if (currentLED == 0) {
59 // Store the current time as the time we last changed LEDs
60 timeChanged = millis();