/*218540787 KF KHANYA*/
// Defining LED pins
const int ledPins[] = {13,12,11,10,9,8,7,4}; //defining an array of LED pins and used pins 13 to 4 for LEDs
const int numLeds = sizeof(ledPins)/sizeof(ledPins[0]); // calculating the number of LEDs in the array
void setup() {
// Setting all LED pins as OUTPUTS
for( int i = 0; i < numLeds; i++){
pinMode(ledPins[i], OUTPUT);
}
}
// Function to flash a single LED
void flashLed(int pin){
digitalWrite(pin, HIGH); // turning on the LEDS
delay(250); // delay to control the speed of the running lights
digitalWrite(pin, LOW); //turning off the LEDS
}
void loop() {
for( int i = 0; i <= numLeds; i++){ //the for loop counts from to 13 to 4 turn ON and OFF every single pin
flashLed(ledPins[i]); // flashes LEDs from pin 13 to 4
}
for( int i = numLeds -1; i >= 0; i--){//the for loop counts from 4 to 13 to turn ON and OFF every single pin
flashLed(ledPins[i]); //flashing LEDs back from pin 4 to 13
}
delay(250); // delay to control the speed of the running lights
}