1 /* Arduino Projects for Dummies
4 * Chapter 4: The All-Seeing Eye
5 * Sequentially lights up a series of LEDs
8 * Changed delayTime variable so that is is consistent with the
9 * text of the book. (Used to be timeDelay.)
11 * Fixed error: timeChanged = millis(); not within if loop brackets
14 // A variable to set a delay time between each LED
17 // A variable to store which LED we are currently working on
20 // A variable to store the direction of travel of LEDs
23 // A variable to store the last time we changed something
24 unsigned long timeChanged = 0;
26 // Create an array to hold the value for each LED pin
27 byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
30 // Set all pins for OUTPUT
31 for (int x=0; x<10; x++) {
32 pinMode(ledPin[x], OUTPUT);
36 timeChanged = millis();
40 // Check whether it has been long enough
41 if ((millis() - timeChanged) > delayTime) {
43 // Turn off all of the LEDs
44 for (int x=0; x<10; x++) {
45 digitalWrite(ledPin[x], LOW);
48 // Turn on the current LED
49 digitalWrite(ledPin[currentLED], HIGH);
51 // Increment by the direction value
54 // If we are at the end of a row, change direction
55 if (currentLED == 9) {
58 if (currentLED == 0) {
63 // Store the current time as the time we last changed LEDs
64 timeChanged = millis();