Interrupts

This library allows you to trigger a process interrupt function or enable/disable an interrupt function when the input to a pin changes value.

attachInterrupt

Description Specifies a function to execute (call) when an external interrupt occurs (signal on external pin).
Syntax attachInterrupt(pin, void(*)(void) func, mode)
Parameters pin: the number of pin using for the interrupt(0, 1, 11, 12)
func: the function to call when the interrupt occurs
mode:
 LOW (to trigger the interrupt whenever the pin is low)
 CHANGE (to trigger the interrupt whenever the pin changes value)
 FALLING (for when the pin goes from high to low)
 RISING (to trigger when the pin goes from low to high)
Returns None

detatachInterrupt

Description Turns off the interrupt specified in attachInterrupt.
Syntax detatachInterrupt(pin)
Parameters pin: the number of pin using for the interrupt(0, 1, 11, 12)
Returns None

interrupts

Description Re-enables the interrupt disabled in noInterrupts.
Syntax interrupts()
Parameters None
Returns None

noInterrupts

Description Disables an interrupt process. Use this when you need to protect the timing of a specific process; this can even be used to disable an important task run in the background.
Syntax noInterrupts()
Parameters None
Returns None


Sample Program

#include <Arduino.h>

void blink()
{
  state = !state;
}

int pin = PIN_LED0;
volatile int state = LOW;

void setup()
{
  pinMode(pin, OUTPUT);
  attachInterrupt(0, blink, CHANGE);
}

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


Made by Gadget Renesas Project
Contents are CC BY-SA 3.0