LED blinking

int LED1 = 13; // Pin number for LED 1
int LED2 = 12; // Pin number for LED 2
int LED3 = 11; // Pin number for LED 3

void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}

void blinkLEDs(int duration) {
for (int i = 0; i < 5; i++) {
// Blink each LED sequentially
digitalWrite(LED1, HIGH); // turn on LED1
delay(duration); // wait for duration
digitalWrite(LED1, LOW); // turn off LED1
delay(duration); // wait for duration
digitalWrite(LED2, HIGH); // turn on LED2
delay(duration); // wait for duration
digitalWrite(LED2, LOW); // turn off LED2
delay(duration); // wait for duration
digitalWrite(LED3, HIGH); // turn on LED3
delay(duration); // wait for duration
digitalWrite(LED3, LOW); // turn off LED3
delay(duration); // wait for duration
}
}

void loop() {
blinkLEDs(1000); // Blink for 1000 milliseconds (1 second)
blinkLEDs(500); // Blink for 500 milliseconds (0.5 seconds)

// Stop the blinking
while (true) {
// Do nothing
}
}

1 Like