This function turns off a given interrupt that was attached previously.
This function has the following variants:
detachInterrupt(digitalPinToInterrupt(pin)) (recommended)detachInterrupt(interrupt) (not recommended)detachInterrupt(pin) (Not recommended. Additionally, this only works on a specific set of boards.)The function admits the following parameters:
interrupt: the number of the interrupt to disable (see attachInterrupt() for more details)pin: the Arduino pin number of the interrupt to disableThe function returns nothing.
void setup() {
// Attach an interrupt on digital pin 2 (assuming you're using it with a button or sensor)
// attachInterrupt(digitalPinToInterrupt(2), myInterruptRoutine, RISING);
// ... other setup code ...
// Later, you can detach the interrupt when you no longer need it
detachInterrupt(digitalPinToInterrupt(2)); // or detachInterrupt(2);
}
void loop() {
// ... your main loop code ...
}
void myInterruptRoutine() {
// This function will be executed when the interrupt on pin 2 is triggered
// and it's still attached. After detachInterrupt(), this routine won't be called.
}