Skip to content

Instantly share code, notes, and snippets.

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