Arduino + Leds Knight Rider Effect

20150915_220640

Arduino Code:

/*
Knight Rider Effect Improved

Knight rider display on 6 LEDs
*/

void setup() {
// set up pins 2 to 8 as outputs
for (int i = 2; i < 7; i++) {
pinMode(i, OUTPUT);
}
}

// function to switch all LEDs off
void allLEDsOff(void)
{
for (int i = 2; i < 7; i++) {
digitalWrite(i, LOW);
}
}

void loop() {
// move on LED to the right
for (int i = 2; i < 6; i++) {
allLEDsOff();
digitalWrite(i, HIGH);
delay(50);
}
// move on LED to the left
for (int i = 6; i > 2; i–) {
allLEDsOff();
digitalWrite(i, HIGH);
delay(50);
}

// move on LED to the right
for (int i = 2; i < 6; i++) {
allLEDsOff();
digitalWrite(i, HIGH);
delay(50);
}
// move on LED to the left
for (int i = 6; i > 2; i–) {
allLEDsOff();
digitalWrite(i, HIGH);
delay(50);
}

allLEDsOff();
delay(250);

}

Advertisements