Arduino MEGA 24 LED Knight Rider Display
In this project, an LED Knight Rider display is built on a breadboard using 24 LEDs.
An Arduino MEGA 2560 is used to directly drive the LEDs from 24 of the Arduino’s pins. An Arduino Uno can not be used to drive the LEDs directly because it has too few pins, although it would be possible to expand the number of outputs on an Arduino Uno using four PCF8574 I/O expander ICs.
const int delay_ms = 50;
void setup() {
int i;
for (i = 30; i <= 53; i++) {
pinMode(i, OUTPUT); // set pins as outputs
digitalWrite(i, LOW); // switch the output pins off
}
}
boolean forward = true; // LED direction flag
int pin_num;
void loop() {
if (forward) { // LEDs left to right
for (pin_num = 30; pin_num <= 53; pin_num++) { digitalWrite(pin_num, HIGH); delay(delay_ms); digitalWrite(pin_num, LOW); } forward = false; } else { // LEDs right to left for (pin_num = 53; pin_num >= 30; pin_num–) {
digitalWrite(pin_num, HIGH);
delay(delay_ms);
digitalWrite(pin_num, LOW);
}
forward = true;
}
}