Arduino_Button_InterruptIn sample code ported.
Fork of InterruptIn_HelloWorld by
Diff: main.cpp
- Revision:
- 1:a219c25967db
- Parent:
- 0:7a20a6aa1f5e
--- a/main.cpp Fri Feb 15 15:13:19 2013 +0000 +++ b/main.cpp Wed Sep 03 11:02:23 2014 +0000 @@ -1,17 +1,33 @@ #include "mbed.h" - -InterruptIn button(p5); + +InterruptIn button(USER_BUTTON); DigitalOut led(LED1); -DigitalOut flash(LED4); - -void flip() { - led = !led; + +void buttonPressed() +{ + led = 1; +} + +void buttonReleased() +{ + led = 0; } - -int main() { - button.rise(&flip); // attach the address of the flip function to the rising edge - while(1) { // wait around, interrupts will interrupt this! - flash = !flash; - wait(0.25); - } + +void setup() +{ + // button.mode(PullUp); + button.rise(&buttonReleased); // attach the address of the buttonReleased function to the rising edge + button.fall(&buttonPressed); // attach the address of the buttonPressed function to the falling edge +} + +void loop() +{ + // put your main code here, to run repeatedly: + +} + +int main() +{ + setup(); + while(1) loop(); } \ No newline at end of file