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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s