Jack Occleshaw
/
w2-timers2
w2timers
main.cpp@0:efb656120fe7, 2017-01-12 (annotated)
- Committer:
- occle
- Date:
- Thu Jan 12 15:43:54 2017 +0000
- Revision:
- 0:efb656120fe7
w2timers
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
occle | 0:efb656120fe7 | 1 | #include "mbed.h" |
occle | 0:efb656120fe7 | 2 | Timer timer_fast; // define Timer with name "timer_fast" |
occle | 0:efb656120fe7 | 3 | Timer timer_slow; // define Timer with name "timer_slow" |
occle | 0:efb656120fe7 | 4 | DigitalOut ledA(LED1); |
occle | 0:efb656120fe7 | 5 | DigitalOut ledB(LED2); |
occle | 0:efb656120fe7 | 6 | void task_fast(void); //function prototypes |
occle | 0:efb656120fe7 | 7 | void task_slow(void); |
occle | 0:efb656120fe7 | 8 | |
occle | 0:efb656120fe7 | 9 | |
occle | 0:efb656120fe7 | 10 | int main() { |
occle | 0:efb656120fe7 | 11 | timer_fast.start(); //start the Timers |
occle | 0:efb656120fe7 | 12 | timer_slow.start(); |
occle | 0:efb656120fe7 | 13 | while (1){ |
occle | 0:efb656120fe7 | 14 | if (timer_fast.read()>0.2){ //test Timer value |
occle | 0:efb656120fe7 | 15 | task_fast(); //call the task if trigger time is reached |
occle | 0:efb656120fe7 | 16 | timer_fast.reset(); //and reset the Timer |
occle | 0:efb656120fe7 | 17 | } |
occle | 0:efb656120fe7 | 18 | if (timer_slow.read()>1){ //test Timer value |
occle | 0:efb656120fe7 | 19 | task_slow(); |
occle | 0:efb656120fe7 | 20 | timer_slow.reset(); |
occle | 0:efb656120fe7 | 21 | } |
occle | 0:efb656120fe7 | 22 | } |
occle | 0:efb656120fe7 | 23 | } |
occle | 0:efb656120fe7 | 24 | void task_fast(void){ //”Fast” Task |
occle | 0:efb656120fe7 | 25 | ledA = !ledA; |
occle | 0:efb656120fe7 | 26 | } |
occle | 0:efb656120fe7 | 27 | void task_slow(void){ //”Slow” Task |
occle | 0:efb656120fe7 | 28 | ledB = !ledB; |
occle | 0:efb656120fe7 | 29 | } |
occle | 0:efb656120fe7 | 30 |