// Define pin numbers
const int buttonPin = 2; // Push button pin
const int ledPin = 13; // LED pin
// Variable to hold the LED state
volatile bool ledState = false;
// Function to handle the button press interrupt
void toggleLED() {
ledState = !ledState; // Toggle the LED state
}
void setup() {
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
// Initialize the button pin as an input with an internal pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
// Attach the interrupt to the button pin, triggering on the FALLING edge
attachInterrupt(digitalPinToInterrupt(buttonPin), toggleLED, FALLING);
}
void loop() {
// Set the LED state based on the ledState variable
digitalWrite(ledPin, ledState ? HIGH : LOW);
}