const int LED_PIN = 6;
const int INTERRUPT_PIN = 3; // can only use pin 2 or pin 3 for ext interrupt
volatile bool ledState = LOW;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(INTERRUPT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), myISR, FALLING); // trigger when button pressed, but not when released.
}
void loop() {
digitalWrite(LED_PIN, ledState);
}
void myISR() {
ledState = !ledState;
// note: LOW == false == 0, HIGH == true == 1, so inverting the boolean is the same as switching between LOW and HIGH.
}