// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = LED_BUILTIN; // the number of the LED pin
// LED_BUILTIN is set to the correct LED pin independent of which board is used
volatile int state = LOW; // To make sure variables shared between an ISR
void buttonPinISR()
{
state = !state; //toggle the state when the interrupt occurs
}
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin), buttonPinISR, FALLING);
}
void loop() {
digitalWrite(ledPin, state); //pin 13 equal the state value
}