Michael Antonucci / Mbed 2 deprecated A3_2_Ticker

Dependencies:   mbed

Revision:
1:76d11e984b8d
Parent:
0:5597320f2dba
Child:
2:302216e564bf
--- a/main.cpp	Sun Oct 04 15:50:17 2020 +0000
+++ b/main.cpp	Sun Oct 04 16:23:47 2020 +0000
@@ -1,24 +1,27 @@
-//Base code for modification for Assignment 2.1
-//Blinks LED2 every 200ms using a single Timer object.
+//Base code for modification for Assignment 3.2
+//Blinks LED2 every 200ms using a single Ticker object.
 //Created: S. Licht, 10/04/2020
+#include "mbed.h"
+Ticker tickerLED2;  //creat ticker object
+DigitalOut LEDOut2(LED2);
 
-#include "mbed.h"
-
-Timer timerLED2;  //creat timer object
-DigitalOut LEDOut2(LED2);
+void changeLED2()  //the function that will be called by the ticker object.
+{
+    LEDOut2 = !LEDOut2;
+}
 
 int main()
 {
-    timerLED2.start(); //start timer counting
+    tickerLED2.attach(&changeLED2,0.2); //the address of the function to call
+    //and the interval in seconds between
+    //calls to that function
 
     while(1) {
-        if (timerLED2.read_ms()>=200) { //check to see if time has been exceeded
-            LEDOut2 = !LEDOut2;
-            timerLED2.reset();  //reset the timer back to zero
-        }  //if timer
-
-        //if you had other code that you wanted to execute faster,
-        //you could put it here!
-        
+        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
 }