Øvingsoppgave fra rep time... med interrupt ..bruker ikke polling i main loop
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:d1e23b548735
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Nov 20 19:25:03 2015 +0000 @@ -0,0 +1,39 @@ +#include "mbed.h" + +DigitalOut led(LED1); +//InterruptIn button(PB_3); +InterruptIn button(PC_13); + +static int ButtonPressed = 0; + +void interruptFall() +{ + ButtonPressed = 1; +} + +void interruptRise() +{ + ButtonPressed = 0; +} + + +int main() { + // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms) + button.mode(PullDown); + button.rise(&interruptRise); + button.fall(&interruptFall); + button.enable_irq(); + + while (true) { + + if (ButtonPressed) + { + led=1; + } + else + { + led=!led; + wait(1); + } + } +} \ No newline at end of file