Created
June 6, 2020 19:22
-
-
Save pyxn/6bf3652ad20d23b6c86f50556b31268f to your computer and use it in GitHub Desktop.
Arduino Uno - Makes an array of 10 LEDs blink systematically in a repeating flow motion
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
const int ledCount = 10; | |
int ledPins[] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; | |
void setup() { | |
for (int i = 0; i < ledCount; i++) { | |
pinMode(ledPins[i], OUTPUT); | |
} | |
} | |
void loop() { | |
for (int i = 0; i < ledCount; i++) { | |
lightLed(i); | |
} | |
for (int i = ledCount - 1; i > 1; i--) { | |
lightLed(i - 1); | |
} | |
} | |
void lightLed(int ledOn) { | |
for (int i = 0; i < ledCount; i++) { | |
if (i == ledOn) { | |
digitalWrite(ledPins[i], HIGH); | |
} else { | |
digitalWrite(ledPins[i], LOW); | |
} | |
} | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment