Stage-1 Students SoCEM / Mbed 2 deprecated Task611Solution

Dependencies:   mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
noutram
Date:
Tue Mar 08 11:47:10 2016 +0000
Commit message:
Task 6.1.1 solution

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib 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 e1ff9b3f13da main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Mar 08 11:47:10 2016 +0000
@@ -0,0 +1,65 @@
+#include "mbed.h"
+#include "rtos.h"
+
+//Function declarations
+void Function1(void const *args);
+void Function2(void const *args);
+void Function3(void const *args);
+
+//I/O
+DigitalOut onBoardLED(LED1);
+DigitalOut redLED(D7);
+DigitalOut yellowLED(D6);
+DigitalOut greenLED(D5);
+
+DigitalIn  onBoardSwitch(USER_BUTTON);
+DigitalIn  SW1(D4);
+DigitalIn  SW2(D3);
+
+Thread* t1;
+Thread* t2;
+Thread* t3;
+
+void Function1(void const *args)
+{
+    while (true) {
+        redLED = !redLED;
+        Thread::wait(2000);
+    }
+}
+
+void Function2(void const *args)
+{
+    while (true) {
+        yellowLED = !yellowLED;
+        Thread::wait(1000);
+    }
+}
+
+//Green Flashing
+void Function3(void const *args)
+{
+    while (true) {
+        greenLED = !greenLED;
+        Thread::wait(500);
+    }
+}
+
+
+//Main thread
+int main() {
+    redLED    = 0;
+    yellowLED = 0;
+    greenLED  = 0;
+    
+    //Create and run threads
+    t1 = new Thread(Function1);           
+    t2 = new Thread(Function2);    
+    t3 = new Thread(Function3);     //Dynamically allocated
+    
+    while(1) {
+        //Thread::wait(osWaitForever);
+        Thread::wait(5000);
+        printf("Awake\n");  //Should not happen
+    }
+}
diff -r 000000000000 -r e1ff9b3f13da mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue Mar 08 11:47:10 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#b4c5542476ba
diff -r 000000000000 -r e1ff9b3f13da mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Mar 08 11:47:10 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/252557024ec3
\ No newline at end of file