Search wiring.org.co:

Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.

Name |

### attachInterrupt()

Examples |
    void setup() {
      // set myFunction to be called everytime
      // interrupt 2 is generated (everytime the pin gets from HIGH to LOW)
      attachInterrupt(EXTERNAL_INTERRUPT_2, myFunction, FALLING);

      // Starts serial to print data
      Serial.begin(9600);
    }

    void loop() {

    }

    void myFunction() {
      // WARNING: you should avoid doing long procedures in interrupt routines
      // Since this is an interrupt routine
      // and Serial is an interrupt driven output
      // interrupts must be enabled before printing
      interrupts();
      Serial.println("Interruption generated");
    }
Description | It is possible to generate and attend external interrupts on the Wiring hardware. On Wiring v1 boards the external interrupts capable pins are: 0, 1, 2, 3, 36, 37, 38 and 39. On Wiring S board the external interrupts capable pins are: 2, 3 and 18. In addition to being regular digital pins, note that some of these pins are also used for libraries like Wire or Serial/Serial1. The attachInterrupt() method sets the function that executes whenver an external interrupt is generated. It also sets the mode in which external interrupts can be triggered depending on the state of the interruption pin, LOW when a pin is low, CHANGE when the pin changes state, RISING when the pin goes from low to high or FALLING when the pin goes from high to low. The Interruption mode can also be set at a later time by using the interruptMode() method. WARNING: you should avoid doing long procedures in interrupt routines, also see the call to interrupts() in the example above enabling interrupts to allow the use of Serial in the interrupt routine.
Syntax |
    attachInterrupt(interrupt, function, mode)
Parameters |

interrupt | The number of the external interrupt: EXTERNAL_INTERRUPT_0, EXTERNAL_INTERRUPT_1 .. etc.
function | The name of the function to be called whenever the interrupt event happens
mode | LOW, CHANGE, RISING or FALLING: the mode the external interrupt is triggered

Returns | None
Usage | Application
Related | detachInterrupt() interruptMode() LOW CHANGE FALLING
RISING

Updated on July 07, 2011 11:07:51pm PDT