How to use Interrupts on the WinoBOARD

Function:

attachInterrupt( Pin, Function, Event )

Pin:
The pin attached as interrupt. Available Pins are:
Digital Pins: 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13
Analog Pins: A0, A1, A2, A3, A4, A5, A7, A8

Function:
The function to call if event was triggered

Event:

  • LOW: to trigger the interrupt whenever the pin is low,
  • CHANGE: to trigger the interrupt whenever the pin changes value
  • RISING: to trigger when the pin goes from low to high,
  • FALLING: for when the pin goes from high to low.
  • HIGH: to trigger the interrupt whenever the pin is high

NOTE: Only one event per pin can be triggered


Example:


bool state = LOW;   //just a variable to store the LED state
int ledPin = 2;     //PIN 2 is connected to the green onboard LED
int interruptPin = A3;  //this pin is the pin which triggers the interrupt event

void setup() {
pinMode(ledPin, OUTPUT);    //turn the LED-pin to an output pin
pinMode(interruptPin, INPUT_PULLUP);        //the normal state (unconnected) of input pin should be HIGH
attachInterrupt(interruptPin, blink, CHANGE);   //This function defines the Interrupt pin and the event
}

void loop() {
digitalWrite(ledPin, state);
}

void blink() {          //this function is called when the intterupt is changing state
  state = !state;       //change the actual state
}