#define BUTTON_PIN 5 // GPIO for the button
#define BUZZER_PIN 4 // GPIO for the buzzer
volatile bool buzzerState = false; // Shared variable to track buzzer state
void IRAM_ATTR handleButtonPress() {
// Toggle the buzzer state
buzzerState = !buzzerState;
digitalWrite(BUZZER_PIN, buzzerState);
}
void setup() {
// Set pin modes
pinMode(BUTTON_PIN, INPUT_PULLUP); // Enable internal pull-up resistor
pinMode(BUZZER_PIN, OUTPUT);
// Attach interrupt to the button pin
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), handleButtonPress, FALLING);
}
void loop() {
// Main loop does nothing, interrupt handles the buzzer
}