Hi Paul,
After attaching the interrupt handling function to an InterruptIn pin, how to detach or disable the handling function in runtime?
The eagle-eyed will spot it in the documentation, but it doesn't exactly jump out at you:
All you do to set there to be no interrupt/handler is set the function to NULL (or 0), like:
InterruptIn interrupt(p20);
interrupt.rise(NULL);
This probably almost answers your second question:
Is it possible to change the handling function in runtime?
Yep! Just use the same technique. Here is a simple test program showing both these cases:
#include "mbed.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
InterruptIn interrupt(p20);
void foo() {
led1 = !led1;
}
void bar() {
led2 = !led2;
}
int main() {
while(1) {
interrupt.rise(&foo);
wait(5);
interrupt.rise(&bar);
wait(5);
interrupt.rise(NULL);
wait(5);
}
}
So in this example, the handler will change every 5 seconds. If you create rising edges on p20 (e.g. tap a wire on p20 connected to VOUT), you should see LED1 responding, then LED2, then nothing. Rinse, repeat.
Hope this answers your question and gives you what you need.
Simon
Hello,
After attaching the interrupt handling function to an InterruptIn pin, how to detach or disable the handling function in runtime?
Is it possible to change the handling function in runtime?
Best regards,
Paul