Example 2

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 handleOtherStuff() {
    delay(250);
}

void loop() {
    handleSW();
    handleOtherStuff();
}

Here, we add some additional processing.  In this case, it takes a while (1/4 second) to do the other stuff.  Doing this other stuff makes the visual feedback sluggish.  Occasionally, inputs may be totally missed.  Polling for short events is difficult if you have lots of other stuff going on.  So, in the next example, we will use an interrupt to make user input snappy again.

Leave a Reply

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

Triangle Embedded Interest Group