Charles Tritt / Mbed 2 deprecated TW_Ex_9_9

Dependencies:   mbed

Fork of TW_Ex_9_1 by Charles Tritt

Revision:
1:c005988842c9
Parent:
0:3151531e9a31
--- a/main.cpp	Fri Oct 06 21:08:45 2017 +0000
+++ b/main.cpp	Mon Oct 09 03:03:12 2017 +0000
@@ -1,33 +1,25 @@
 /*
-    Project: TW_Ex_9_1
+    Project: TW_Ex_9_9
     File: main.cpp
-    
-    An example similar to T&W example 9.1. Green junction will flash 
-    continuously. Blue junction will toggle in response to depressing the user 
-    button.
-    
-    Created by Dr. C. S. Tritt
-    Last revised: 10/6/17 (v. 1.0)
+
+    An example similar to T&W example 9.9. imple demo of "Ticker". Replicates 
+    behaviour of first led flashing program.
+
+    Modified by Dr. C. S. Tritt
+    Last revised: 10/8/17 (v. 1.0)
 */
+
 #include "mbed.h"
 
-InterruptIn myButton(USER_BUTTON); // Button is normally high. Goes low w/press.
+void led_switch(void); // Ticker callback declaration.
+Ticker time_up; // Define a Ticker named "time_up."
+DigitalOut myled(D4); // Blue LED junction.
 
-DigitalOut bluLED(D4); // Bluee and green LED junctions.
-DigitalOut grnLED(D3);
-
-void myISR() { // Simple ISR toggles the red LED junction when called.
-    bluLED = !bluLED; // Toggle blue junction.
+int main(){
+    time_up.attach(&led_switch, 0.2); // Initialize Ticker. 0.2 s interval.
+    while(1) {} // Sit in a loop doing nothing, waiting for Ticker interrupt.
 }
 
-int main() {
-    bluLED = 0; // Turn blue & green off at start.
-    grnLED = 0; 
-    
-    myButton.fall(&myISR); // "Register" the ISR routine. Sets vector.
-    
-    while(true) {
-        grnLED = !grnLED; // Toggle green junction.
-        wait(0.5); // Pause half a second.
-    }
+void led_switch() {  // Ticker callback.
+    myled=!myled;
 }
\ No newline at end of file