by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

Revision:
0:063d9f9ab154
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 24 21:47:49 2013 +0000
@@ -0,0 +1,33 @@
+/*Program Example 9.4: Program which runs two time-based tasks
+                                                                       */
+#include "mbed.h"
+Timer timer_fast;                    // define Timer with name "timer_fast"
+Timer timer_slow;                    // define Timer with name "timer_slow"
+DigitalOut ledA(LED1);
+DigitalOut ledB(LED4);
+
+void task_fast(void);                //function prototypes
+void task_slow(void);
+
+int main() {
+  timer_fast.start();    //start the Timers
+  timer_slow.start(); 
+  while (1){
+    if (timer_fast.read()>0.2){  //test Timer value
+      task_fast();               //call the task if trigger time is reached
+      timer_fast.reset();            //and reset the Timer
+    }
+    if (timer_slow.read()>1){     //test Timer value
+      task_slow();
+      timer_slow.reset();
+    }
+  }
+}
+
+void task_fast(void){          //”Fast” Task
+  ledA = !ledA;
+}
+void task_slow(void){         //”Slow” Task
+  ledB = !ledB;
+}
+