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
28 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
31 // Set all pins for OUTPUT with a counter
32 for (int x=0; x<10; x++) {
33 pinMode(ledPin[x], OUTPUT);
36 // Set all pins for OUTPUT iterating a pointer
37 // byte *ptr = ledPin ;
39 // pinMode(*ptr++, OUTPUT);
43 timeChanged = millis();
47 // Check whether it has been long enough
48 if ((millis() - timeChanged) > delayTime) {
49 // Turn off all of the LEDs, see next comment
50 for (int x=0; x<10; x++) {
51 digitalWrite(ledPin[x], LOW);
53 // Turning off just one LED instead on 10 would be more efficient
54 // digitalWrite(ledPin[currentLED - dir], LOW);
56 // Turn on the current LED
57 digitalWrite(ledPin[currentLED], HIGH);
59 // Increment by the direction value
62 // If we are at the end of a row, change direction
63 if (currentLED == 9) {
66 if (currentLED == 0) {
70 // Let's change the speed wit a Pot on pin A5
71 // delayTime = map(analogRead(5),0,1024,20,5 00);
74 // Store the current time as the time we last changed LEDs
75 timeChanged = millis();