// Define the GPIO pins for the LEDs and the pushbutton
#define LED1 5
#define LED2 4
#define BUTTON_PIN 12
volatile bool led3State = LOW;
void IRAM_ATTR handleButtonPress() {
// Toggle the state of the third LED
led3State = !led3State;
digitalWrite(BUTTON_PIN, led3State);
}
void setup() {
// Initialize the GPIO pins as outputs
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(BUTTON_PIN, OUTPUT);
// Initialize the pushbutton pin as an input
pinMode(BUTTON_PIN, INPUT_PULLUP);
// Attach an interrupt to the pushbutton pin
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), handleButtonPress, FALLING);
}
void loop() {
// Blink the first LED every 250ms
digitalWrite(LED1, HIGH); // Turn on LED1
delay(250); // Wait for 250ms
digitalWrite(LED1, LOW); // Turn off LED1
delay(250); // Wait for 250ms
// Blink the second LED every 500ms
digitalWrite(LED2, HIGH); // Turn on LED2
delay(500); // Wait for 500ms
digitalWrite(LED2, LOW); // Turn off LED2
delay(500); // Wait for 500ms
// The third LED is controlled by the interrupt and pushbutton
}