Created
June 12, 2017 16:00
-
-
Save gjbagrowski/516236dac196bf6ad4c1ba5a3dcd905c to your computer and use it in GitHub Desktop.
Knight Rider leds for particle
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 leds[] = {D4, D3, D2, D1, D0}; | |
int led_count = 5; | |
int timer = 15; | |
void setup() { | |
for (int i = 0; i < led_count; i++) { | |
pinMode(leds[i], OUTPUT); | |
} | |
} | |
void activateLed(int led, int direction) { | |
for (int i = 0; i < led_count; i++) { | |
if (i == led || i == led + direction) { | |
digitalWrite(leds[i], HIGH); | |
delay(timer); | |
} else { | |
digitalWrite(leds[i], LOW); | |
delay(timer * 2); | |
} | |
} | |
} | |
void loop() { | |
for (int i = 0; i < led_count; i++) { | |
activateLed(i, -1); | |
} | |
for (int i = led_count -1; i >= 0; i--) { | |
activateLed(i, 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment