The function connects the user's interrupt handler to the external interrupt pin. This allows you to avoid periodic checking of a pin and respond only to a event on a pin. Typical tasks when need do it is responding to a rotary encoder or a button.
void attachInterrupts(uint8_t interruptNum, void (userFunc*)(void), int mode);
digitalPinToInterruptto get it. You can only use pins, that allow external interrupts.
|Board||Useable digital pins|
|Uno, Nano, Mini||2, 3|
|Mega||2, 3, 18, 19, 20, 21|
|Micro, Leonardo||0, 1, 2, 3, 7|
|Zero||All digital pins except 4.|
|MKR1000||0, 1, 4, 5, 6, 7, 8, 9, A1, A2|
|Due||All digital pins.|
The pin numbers that support interrupts are different than digital pins. To avoid having to remember them, you can use the macro
digitalPinToInterrupt(pin). In many examples you find on the Internet, this macro is not used. I'm not an exception, and many of my older codes do not use this macro.
Here are some examples of use.