Created
August 24, 2016 08:31
-
-
Save prasant1010/f3d1f5a0a72c95ca2e794caa676f847d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int time = 500; // The higher the number, the slower the timing. | |
int ledPins[] = { 0,1,2,3,4,5,6,7 }; // an array of pin numbers to which LEDs are attached | |
int pinCount = 8; // the number of pins (i.e. the length of the array) | |
void setup() { | |
// the array elements are numbered from 0 to (pinCount - 1). | |
// use a for loop to initialize each pin as an output: | |
for (int thisPin = 0; thisPin < pinCount; thisPin++) { | |
pinMode(ledPins[thisPin], OUTPUT); | |
} | |
} | |
void loop() { | |
// loop from the lowest pin to the highest: | |
for (int thisPin = 0; thisPin < pinCount; thisPin++) { | |
// turn the pin on: | |
digitalWrite(ledPins[thisPin], HIGH); | |
delay(time); | |
// turn the pin off: | |
digitalWrite(ledPins[thisPin], LOW); | |
} | |
// loop from the highest pin to the lowest: | |
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { | |
// turn the pin on: | |
digitalWrite(ledPins[thisPin], HIGH); | |
delay(time); | |
// turn the pin off: | |
digitalWrite(ledPins[thisPin], LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment