const int buttonPin = 18; // GPIO pin for button
const int ledPin = 2; // GPIO pin for LED
volatile bool ledState = false; // Use volatile for shared variables
void IRAM_ATTR handleInterrupt() {
ledState = !ledState; // Toggle LED state
}
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin), handleInterrupt, FALLING);
Serial.begin(115200);
}
void loop() {
digitalWrite(ledPin, ledState); // Update LED based on interrupt
Serial.print("LED State: ");
Serial.println(ledState ? "ON" : "OFF");
delay(100); // Small delay for serial output stability
}