int ledPins[] = {9, 8, 7, 6, 5, 4, 3, 2}; // Set the digital pin numbers for the LEDs
int ledCount = sizeof(ledPins)/sizeof(int); // Count the number of LEDs
int pattern = 0; // Initialize the pattern to 0
void setup() {
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT); // Set the LED pins as outputs
}
}
void loop() {
if (pattern == 0) { // Blink each LED one by one
for (int i = 0; i < ledCount; i++) {
digitalWrite(ledPins[i], HIGH); // Turn on the LED
delay(200); // Wait for a short time
digitalWrite(ledPins[i], LOW); // Turn off the LED
delay(200); // Wait for a short time
}
}
else if (pattern == 1) { // Blink two LEDs at a time
for (int i = 0; i < ledCount; i += 2) {
digitalWrite(ledPins[i], HIGH); // Turn on the first LED
digitalWrite(ledPins[i+1], HIGH); // Turn on the second LED
delay(400); // Wait for a short time
digitalWrite(ledPins[i], LOW); // Turn off the first LED
digitalWrite(ledPins[i+1], LOW); // Turn off the second LED
delay(400); // Wait for a short time
}
}
else if (pattern == 2) { // Blink four LEDs at a time
for (int i = 0; i < ledCount; i += 4) {
digitalWrite(ledPins[i], HIGH); // Turn on the first LED
digitalWrite(ledPins[i+1], HIGH); // Turn on the second LED
digitalWrite(ledPins[i+2], HIGH); // Turn on the third LED
digitalWrite(ledPins[i+3], HIGH); // Turn on the fourth LED
delay(600); // Wait for a short time
digitalWrite(ledPins[i], LOW); // Turn off the first LED
digitalWrite(ledPins[i+1], LOW); // Turn off the second LED
digitalWrite(ledPins[i+2], LOW); // Turn off the third LED
digitalWrite(ledPins[i+3], LOW); // Turn off the fourth LED
delay(600); // Wait for a short time
}
}
else if (pattern == 3) { // Turn on all LEDs at once
for (int i = 0; i < ledCount; i++) {
digitalWrite(ledPins[i], HIGH); // Turn on all the LEDs
}
delay(800); // Wait for a longer time
for (int i = 0; i < ledCount; i++) {
digitalWrite(ledPins[i], LOW); // Turn off all the LEDs
}
}
pattern++; // Increment the pattern index
if (pattern > 3) {
pattern = 0; // Reset the pattern index if it goes beyond 3
}
}