chipKIT® Development Platform

Inspired by Arduino™

Last edit: 2021-03-21 22:34 by Majenko

AttachInterrupt

  1. Synopsis

  2. Description

  3. Return Value

  4. Modes

  5. Conforming To

  6. Examples

  7. See Also

Synopsis

 void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)

Description

The attachInterrupt() function connects an external interrupt pin (INTx) to a user provided function. The interrupt function is automatically called by the interrupt controller when the level of the input pin changes either from LOW to HIGH or vice versa. The interrupt can be triggered only on one of those transitions, and not both. interruptNum is the number of the interrupt to connect to (not the pin number) which is documented in the manual for your board. The userFunc is a pointer to a user-provided function. mode is one of RISING or FALLING. The traditional Arduino API also provides the CHANGE mode but, due to hardware constraints, this mode is not supported.

Return Value

None

Modes

  • RISING The interrupt will trigger when the logic level changes from LOW to HIGH.

  • FALLING The interrupt will trigger when the logic level changes from HIGH to LOW.

Conforming To

attachInterrupt() conforms to the Arduino 1.6.x API with the following exception:

  • No support for the CHANGE mode

Examples

A simple interrupt to toggle an output when an interrupt is triggered:

 void myInterrupt() {
     static boolean state = false;
     state = !state;
     digitalWrite(13, state);
 }

 attachInterrupt(0, myInterrupt, FALLING);

See Also

detachInterrupt(), clearIntEnable(), clearIntFlag(), clearIntVector(), disableInterrupts(), enableInterrupts(), getIntFlag(), getIntPriority(), getIntVector(), restoreIntEnable(), restoreInterrupts(), setIntEnable(), setIntPriority(), setIntVector()