timer 3
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:83d0531fdf71
diff -r 000000000000 -r 83d0531fdf71 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 23 18:23:19 2014 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" +Timer timer1; // define timer object +DigitalOut output1(LED_RED); // digital output +void task1(void); // task function prototype +Timer timer2; // define timer object +DigitalOut output2(LED_BLUE); // digital output +void task2(void); // task function prototype + +//*** main code +int main() { + timer1.start(); // start timer1 counting + timer2.start(); // start timer2 counting + while(1) { + if (timer1.read_ms()>=200) // read time + { + task1(); // call task1 function + timer1.reset(); // reset timer + } + if (timer2.read_ms()>=1000) // read time + { + task2(); // call task2 function + timer2.reset(); // reset timer + } + } +} +//*** task functions +void task1(void){ + output1=!output1; // toggle output1 +} +void task2(void){ + output2=!output2; // toggle output2 +}