#define LED_PIN 4
#define BUTTON_PIN 15
volatile bool ledState = false; // state of LED (volatile because it's changed in ISR)
// Interrupt Service Routine (ISR)
void IRAM_ATTR handleButtonPress() {
ledState = !ledState; // toggle LED
digitalWrite(LED_PIN, ledState);
}
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP); // enable internal pull-up
// Attach interrupt
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), handleButtonPress, FALLING);
Serial.begin(115200);
Serial.println("Button interrupt example started.");
}
void loop() {
// Main loop does nothing; LED is controlled by ISR
}