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 |
|
||||||
Returns | None | ||||||
Usage | Application | ||||||
Related | detachInterrupt() interruptMode() LOW CHANGE FALLING RISING |