A ticker used to generate a periodic timer interrupt

Dependencies:   mbed

Fork of Timeout_HelloWorld by mbed official

Revision:
1:04a6abc32fe7
Parent:
0:8a555873b7d3
--- a/main.cpp	Fri Feb 15 14:39:20 2013 +0000
+++ b/main.cpp	Mon May 09 11:29:17 2016 +0000
@@ -1,20 +1,50 @@
+/* 
+Task3_Ticker
+Sample code from ELEC2645 Week 15 Lab
+Demonstrates how to use a ticker to generate a periodic timer interrupt
+(c) Bonny Ngangu, University of Leeds, Jan 2016
+*/ 
+// Toggle the blinking led after 5 seconds
+
 #include "mbed.h"
- 
-Timeout flipper;
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
- 
-void flip() {
-    led2 = !led2;
+
+Timeout timer;
+InterruptIn sw3(SW3);
+
+DigitalOut led1(LED_RED);
+DigitalOut led2(LED_GREEN);
+DigitalOut led3(LED_BLUE);
+
+BusOut output(PTB2,PTB3,PTB10,PTB11,PTC11);
+
+volatile int g_blue_timer_flag = 0;
+volatile int g_sw3_flag = 0;
+
+int flip = 0;
+
+void attime()
+{
+    led3 = 0; // turn on LED
+    led2 = 1;
+    led1 = 1;
 }
- 
-int main() {
-    led2 = 1;
-    flipper.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds
- 
-    // spin in a main loop. flipper will interrupt it to call flip
+void blue_timer_isr();
+void sw3_isr();
+
+int main()
+{
+    led3 = 1;
+    sw3.fall(&sw3_isr);
+    sw3.mode(PullNone);
+
     while(1) {
-        led1 = !led1;
-        wait(0.2);
+    if (g_sw3_flag) {
+            g_sw3_flag = 0;
+    timer.attach(&attime, 5);
+        }
     }
+}
+void sw3_isr()
+{
+    g_sw3_flag = 1;   // set flag in ISR
 }
\ No newline at end of file