Skip to content

Instantly share code, notes, and snippets.

@gjbagrowski
Created June 12, 2017 16:00
Show Gist options
  • Save gjbagrowski/516236dac196bf6ad4c1ba5a3dcd905c to your computer and use it in GitHub Desktop.
Save gjbagrowski/516236dac196bf6ad4c1ba5a3dcd905c to your computer and use it in GitHub Desktop.
Knight Rider leds for particle
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