/* Arduino Projects for Dummies * by Brock Craft * * Chapter 4: The All-Seeing Eye * Sequentially lights up a series of LEDs * * v0.1 30.04.2013 */ // A variable to set a delay time between each LED int timeDelay(40); // A variable to store which LED we are currently working on int currentLED = 4; // A variable to store the direction of travel of LEDs int dir = 1; // A variable to store the last time we changed something unsigned long timeChanged = 0; // Create an array to hold the value for each LED pin byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; void setup() { // Set all pins for OUTPUT for (int x=0; x<10; x++) { pinMode(ledPin[x], OUTPUT); } // Set up the timeChanged = millis(); } void loop() { // Check whether it has been long enough if ((millis() - timeChanged) > timeDelay) { // Turn off all of the LEDs for (int x=0; x<10; x++) { digitalWrite(ledPin[x], LOW); } // Turn on the current LED digitalWrite(ledPin[currentLED], HIGH); // Increment by the direction value currentLED += dir; // If we are at the end of a row, change direction if (currentLED == 9) { dir = -1; } if (currentLED == 0) { dir = 1; } } // Store the current time as the time we last changed LEDs timeChanged = millis(); }