

The change in the pin is detected by a CHANGE interrupt, which causes the Interrupt Service Routine (ISR) to be called. The internal pullup (enabled in setup) forces the pin HIGH normally. To test this, just connect a wire (or switch) between D2 and Ground. This example shows how, even though the main loop is doing nothing, you can turn the LED on pin 13 on or off, if the switch on pin D2 is pressed. PinMode (LED, OUTPUT) // so we can update the LEDĭigitalWrite (BUTTON, HIGH) // internal pull-up resistorĪttachInterrupt (digitalPinToInterrupt (BUTTON), switchPressed, CHANGE) // attach interrupt handler
