Stage-1 Students SoCEM / Mbed 2 deprecated TickerDemo

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
noutram
Date:
Thu Sep 24 12:32:36 2015 +0000
Commit message:
Initial version 24-09-2015

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 8ee1b72f9a9b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 24 12:32:36 2015 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+
+
+//Global objects
+DigitalOut myled(LED1);
+Serial pc(USBTX, USBRX);
+Ticker t;
+
+//Integer state of the LED
+//static makes it visible only within main.cpp
+static int state = 0;
+
+//Function prototype
+void doISR();
+
+int main() {
+   
+   //Initialise
+   pc.baud(115200);
+   t.attach(&doISR, 2);
+   myled = 0;
+    
+    //Main loop
+    while(1) {
+        
+        //Go to sleep and wait for an ISR to wake
+        sleep();    //At is says
+        
+        //At this point, the ISR has run
+        
+        //Update LED
+        myled = state;
+        
+        //Echo to terminal
+        if (state == 0) {
+            pc.printf("LED OFF\n");
+        } else {
+            pc.printf("LED ON\n");   
+        }
+    }
+}
+
+//Note - the ISR is short, and does NOT call functions
+//such as printf (it's actually unsafe to do so)
+//Always check a function is "reentrant" before calling it
+void doISR() {
+    //Toggle 0 to 1, or 1 to 0
+    state ^= 1;      
+}
\ No newline at end of file
diff -r 000000000000 -r 8ee1b72f9a9b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 24 12:32:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad
\ No newline at end of file