From chipKIT
Jump to: navigation, search


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


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




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


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


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()