Loading...
Searching...
No Matches
Interrupts

attachInterrupt(), detachInterrupt(), interrupts(), noInterrupts(). More...

Macros

#define interrupts()
#define noInterrupts()
#define digitalPinToInterrupt(pin)

Functions

void attachInterrupt (pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode)
 Calls a function when the level on a pin changes.
void attachInterruptParam (pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void *param)
 Same as attachInterrupt(), but the function is called with param.
void detachInterrupt (pin_size_t interruptNumber)
 Stops calling the function attached to a pin.

Detailed Description

Macro Definition Documentation

◆ digitalPinToInterrupt

#define digitalPinToInterrupt ( pin)
Value:
(pin)

Interrupt number for attachInterrupt(): every pin can interrupt, so it is the pin itself.

◆ interrupts

#define interrupts ( )
Value:
__asm volatile("cpsie i" ::: "memory")

Enables interrupts again after noInterrupts().

◆ noInterrupts

#define noInterrupts ( )
Value:
__asm volatile("cpsid i" ::: "memory")

Disables interrupts, for example while reading a variable an interrupt changes. Keep the section short: USB Serial, attachInterrupt() functions and tone() durations wait until interrupts() (millis() keeps counting). Only the calling core is affected: the other core keeps running (Multicore).

Function Documentation

◆ attachInterrupt()

void attachInterrupt ( pin_size_t interruptNumber,
voidFuncPtr callback,
PinStatus mode )

Calls a function when the level on a pin changes.

Unlike an Uno (D2 and D3 only), every pin except A3-A5 can interrupt. Replaces any function already attached to the pin.

Parameters
interruptNumberdigitalPinToInterrupt(pin), which is just the pin number.
callbackFunction to call; nullptr is ignored.
modeRISING, FALLING or CHANGE; or LOW or HIGH, which call the function again as soon as it returns, for as long as the level lasts.
Warning
The function runs inside the interrupt: keep it short, make variables it shares with loop() volatile, and do not use Serial or delay() in it.

◆ attachInterruptParam()

void attachInterruptParam ( pin_size_t interruptNumber,
voidFuncPtrParam callback,
PinStatus mode,
void * param )

Same as attachInterrupt(), but the function is called with param.

Parameters
interruptNumberdigitalPinToInterrupt(pin), which is just the pin number.
callbackFunction taking a void*; nullptr is ignored.
modeAs for attachInterrupt().
paramPassed to callback on every call.

◆ detachInterrupt()

void detachInterrupt ( pin_size_t interruptNumber)

Stops calling the function attached to a pin.

Parameters
interruptNumberdigitalPinToInterrupt(pin), which is just the pin number.