Example 1

Back to Arduino Interrupts

const byte LED = 13, SW = 2;

void setup() {
    pinMode(LED, OUTPUT);
    pinMode(SW, INPUT_PULLUP);

void handleSW() {
    digitalWrite(LED, digitalRead(SW));

void loop() {

This is a really simple example, where we have a normally open momentary pushbutton between pin 2 and ground. Pin 2 is pulled up internally and will read HIGH unless the pushbutton is closed.  Using good Human Machine Interface guidelines, we indicate receipt of the user input by toggling the LED.  If you run this, the LED will go out as soon as you press the button (at least on a human time scale) and come back on when you release the button.

Leave a Reply

Your email address will not be published. Required fields are marked *

Triangle Embedded Interest Group