Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 4:90f9fff2e44e
- Parent:
- 3:f6547e1c1dfc
- Child:
- 5:f7e87403aca4
--- a/main.cpp Thu Oct 21 13:43:27 2021 +0000 +++ b/main.cpp Thu Oct 21 14:19:43 2021 +0000 @@ -2,10 +2,14 @@ //Blinks LED2 every 200ms using a single Ticker object. //Created: S. Licht, 10/04/2020 #include "mbed.h" +Ticker tickerLED1; Ticker tickerLED2; //create ticker object -Ticker tickerLED3; +Ticker tickerLED3; +DigitalOut LEDOut1(LED1); DigitalOut LEDOut2(LED2); DigitalOut LEDOut3(LED3); +InterruptIn butn(p17); //Interupts with pushbutton input p17 +Timer debounce; //define debounce timer void changeLED2() //the function that will be called by the ticker object. { @@ -17,16 +21,21 @@ LEDOut3 = !LEDOut3; } +void toggle() +{ + if (debounce.read_ms()>200) { //only allow toggle if debounce timer + LEDOut1=!LEDOut1; //has passed 200ms + debounce.reset(); //restart timer when toggle is performed + } +} int main() { - tickerLED2.attach(&changeLED2,0.2); //the address of the function to call - //and the interval in seconds between - //calls to that function - + debounce.start(); //start + butn.rise(&toggle); + tickerLED2.attach(&changeLED2,0.2); //the address of the function to call and the interval in seconds between calls to that function tickerLED3.attach(&changeLED3,0.3); - - - //the main loop is spinning every 500ms, but the LED needs to go faster! - //while } + + +