Created
March 30, 2014 22:35
-
-
Save gjbagrowski/9881086 to your computer and use it in GitHub Desktop.
Knight rider leds, spark core version.
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