//#include <Arduino.h>
// Pin for the button
const int buttonPin = 2;
// A flag that gets set when the button is pressed
volatile bool buttonPressed = false;
// Callback function (ISR) that is triggered when the button is pressed
void buttonISR() {
buttonPressed = true; // Set the flag when the button is pressed
}
void setup() {
Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP); // Set button pin as input with pull-up resistor
// Attach interrupt to button pin: trigger ISR on falling edge (button press)
attachInterrupt(digitalPinToInterrupt(buttonPin), buttonISR, FALLING);
}
void loop() {
// Check if the button was pressed (ISR sets the flag)
if (buttonPressed) {
delay(50);
Serial.println("Button was pressed!");
buttonPressed = false; // Reset the flag after processing
}
}