#include <avr/io.h>
#include <avr/interrupt.h>
volatile uint8_t currentLED = 0; // Index of the current LED
const uint8_t ledPins[5] = {3, 4, 5, 6, 7}; // LED pin numbers
void setup() {
// Set the LED pins as outputs
for (int i = 0; i < 5; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW); // Ensure LEDs are off initially
}
// Set the external interrupt pin as input
pinMode(2, INPUT_PULLUP); // Use internal pull-up resistor
// Configure external interrupt on pin 2 (INT0)
noInterrupts(); // Disable all interrupts
EICRA |= (1 << ISC01); // Trigger on falling edge of INT0
EIMSK |= (1 << INT0); // Enable external interrupt INT0
interrupts(); // Enable all interrupts
}
ISR(INT0_vect) {
// Toggle the current LED
digitalWrite(ledPins[currentLED], !digitalRead(ledPins[currentLED]));
// Move to the next LED in the pattern
currentLED++;
if (currentLED >= 7) {
currentLED = 0;
}
}
void loop() {
// The loop is intentionally left empty
}