![](/media/cache/profiles/1c65edfdcd4ef282f3953f359c5e7209.jpg.50x50_q85.jpg)
Blinky example with two pushbuttons
Fork of mbed_blinky_low_power by
main.cpp
00001 #include "mbed.h" 00002 00003 DigitalOut myled0(LED0); 00004 DigitalOut myled1(LED1); 00005 InterruptIn pb0(SW0); 00006 InterruptIn pb1(SW1); 00007 00008 LowPowerTicker toggleTicker; 00009 00010 float new_freq = 0.2f; 00011 bool ledblink = true; 00012 00013 00014 // Callback for toggler 00015 void ledToggler(void) { 00016 myled0 = !myled0 * ledblink; 00017 myled1 = !myled1 * (1-ledblink); 00018 } 00019 00020 // Callback for pushbutton interrupt 00021 void pb0_handler() { 00022 ledblink = !ledblink; 00023 } 00024 00025 void pb1_handler() { 00026 if (ledblink) { 00027 new_freq = new_freq/2; 00028 } 00029 else { 00030 new_freq = new_freq*2; 00031 } 00032 } 00033 00034 int main() { 00035 float freq = 0.0f; 00036 //Enable the PB-handler 00037 pb0.rise(NULL); 00038 pb0.fall(&pb0_handler); 00039 00040 pb1.rise(NULL); 00041 pb1.fall(&pb1_handler); 00042 00043 while(1) { 00044 if (freq != new_freq) { 00045 toggleTicker.detach(); 00046 toggleTicker.attach(&ledToggler, new_freq); 00047 freq = new_freq; 00048 } 00049 sleep(); 00050 } 00051 }
Generated on Tue Aug 2 2022 09:19:24 by
![doxygen](doxygen.png)