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.
main.cpp
- Committer:
- markschwarzer
- Date:
- 2020-10-12
- Revision:
- 2:39e295fcc23d
- Parent:
- 1:fdcb0bfe75b7
- Child:
- 3:be25235bbac5
File content as of revision 2:39e295fcc23d:
//Mark Schwarzer Assignment 4 #include "mbed.h" Ticker tickerLED1; //creat ticker object Ticker tickerLED3; DigitalOut LEDOut1(LED1); DigitalOut LEDOut3(LED3); InterruptIn button(p17); Timer debounce; void toggle(void); int main() { debounce.start(); button.rise(&toggle); //toggle function to rising edge } void toggle() { if (debounce.read_ms()>200); //allow toggle if debounce timer has passed 200 ms LEDOut1 = !LEDOut1; debounce.reset(); //restart timer at toggle } void changeLED1() //the function that will be called by the ticker object. { LEDOut1 = !LEDOut1; } void changeLED3() //function called for other ticker object LED3 { LEDOut3 = !LEDOut3; } int second() { tickerLED1.attach(&changeLED1,0.2); //the address of the function to call //and the interval in seconds between //calls to that function tickerLED3.attach(&changeLED3,0.8); //changing the interval in seconds for LED3 while(1) { wait(0.1); wait(0.1); wait(0.1); wait(0.1); wait(0.1); //the main loop is spinning every 500ms, but the LED needs to go faster! } //while }