Hi
I've observed some behaviour I can't explain with InterruptIn and wondered if somebody could shed some light.
The code below (and here http://mbed.org/users/mbed714/programs/gpdz5e) is an extended version of the example in the handbook. In my case I have normally open switches wired to ground so require a pull up mode and a fall rather than rise method, and I also have two switches.
#include "mbed.h"
InterruptIn button(p5);
InterruptIn button2(p6);
DigitalOut led(LED1);
DigitalOut led2(LED2);
DigitalOut flash(LED4);
void flip() {
led = !led;
}
void flip2() {
led2 = !led2;
}
int main() {
button.mode(PullUp);
button2.mode(PullUp);
button.fall(&flip); // attach the address of the flip function to the falling edge
button2.fall(&flip2);
while (1) { // wait around, interrupts will interrupt this!
flash = !flash;
wait(0.25);
}
}
When running the program, without pressing any switches LED1 is lit (LED2 is unlit). I would expect both to be unlit until a button press.
Now if I reverse the order of the calls to fall, as follows ...
button2.fall(&flip2);
button.fall(&flip); // attach the address of the flip function to the falling edge
When running the program again, LED2 is lit and LED1 is unlit.
It looks like the first call to fall causes the handler to actually be entered. The second call to fall doesn't. Is this behaviour by design, can it be worked around? I don't want the handler to be called until my button is pressed and I get the real falling edge.
Thanks, Daniel
Hi
I've observed some behaviour I can't explain with InterruptIn and wondered if somebody could shed some light.
The code below (and here http://mbed.org/users/mbed714/programs/gpdz5e) is an extended version of the example in the handbook. In my case I have normally open switches wired to ground so require a pull up mode and a fall rather than rise method, and I also have two switches.
When running the program, without pressing any switches LED1 is lit (LED2 is unlit). I would expect both to be unlit until a button press.
Now if I reverse the order of the calls to fall, as follows ...
When running the program again, LED2 is lit and LED1 is unlit.
It looks like the first call to fall causes the handler to actually be entered. The second call to fall doesn't. Is this behaviour by design, can it be worked around? I don't want the handler to be called until my button is pressed and I get the real falling edge.
Thanks, Daniel