Created
December 7, 2015 02:10
-
-
Save christophervigliotti/67aceea416c7b62a920a to your computer and use it in GitHub Desktop.
Three LED Array PEW PEW!
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 timer = 100; // The higher the number, the slower the timing. | |
int ledPins[] = { | |
2, 3, 4 | |
}; // an array of pin numbers to which LEDs are attached | |
int pinCount = 3; // 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(timer); | |
// 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(timer); | |
// 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