Blinky example with two pushbuttons
Fork of mbed_blinky_low_power by
Revision 3:82208e3277e8, committed 2015-05-18
- Comitter:
- Laplace
- Date:
- Mon May 18 10:06:54 2015 +0000
- Parent:
- 2:6528df2ef648
- Commit message:
- Created a dual pushbutton blinky example.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6528df2ef648 -r 82208e3277e8 main.cpp --- a/main.cpp Wed Apr 29 21:23:49 2015 +0000 +++ b/main.cpp Mon May 18 10:06:54 2015 +0000 @@ -1,15 +1,51 @@ #include "mbed.h" - -DigitalOut myled(LED1); + +DigitalOut myled0(LED0); +DigitalOut myled1(LED1); +InterruptIn pb0(SW0); +InterruptIn pb1(SW1); + LowPowerTicker toggleTicker; +float new_freq = 0.2f; +bool ledblink = true; + + +// Callback for toggler void ledToggler(void) { - myled = !myled; + myled0 = !myled0 * ledblink; + myled1 = !myled1 * (1-ledblink); +} + +// Callback for pushbutton interrupt +void pb0_handler() { + ledblink = !ledblink; +} + +void pb1_handler() { + if (ledblink) { + new_freq = new_freq/2; + } + else { + new_freq = new_freq*2; + } } int main() { - toggleTicker.attach(&ledToggler, 0.2f); + float freq = 0.0f; + //Enable the PB-handler + pb0.rise(NULL); + pb0.fall(&pb0_handler); + + pb1.rise(NULL); + pb1.fall(&pb1_handler); + while(1) { + if (freq != new_freq) { + toggleTicker.detach(); + toggleTicker.attach(&ledToggler, new_freq); + freq = new_freq; + } sleep(); } } \ No newline at end of file
diff -r 6528df2ef648 -r 82208e3277e8 mbed.bld --- a/mbed.bld Wed Apr 29 21:23:49 2015 +0000 +++ b/mbed.bld Mon May 18 10:06:54 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/8ab26030e058 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/dbbf35b96557 \ No newline at end of file