University of Plymouth - Stages 1, 2 and 3 / Mbed OS Task330
Revision:
3:a39db8aa11e8
Parent:
2:ca251bdda621
Child:
4:f30ca79f4676
--- a/main.cpp	Mon Oct 23 12:25:13 2017 +0000
+++ b/main.cpp	Mon Oct 23 12:28:09 2017 +0000
@@ -4,10 +4,6 @@
 #define RELEASED 0
 #define PRESSED  1
 
-//Function prototypes
-void blockOnSwitch1();
-void blockOnSwitch2();
-
 //Hardware objects
 DigitalOut red_led(PE_15);     //CountUp is in its critical section
 DigitalOut yellow_led(PB_10);  //CountDown is in its critical section
@@ -30,12 +26,21 @@
     
     //Now loop forever
     while(1) { 
-        
-        //Wait for user to press and release sw1
-        blockOnSwitch1();
+    
+        while (sw1 == RELEASED) {};
+        wait(0.2);
+        while (sw1 == PRESSED) {};    
+        red_led = !red_led;
+        wait(0.2);
 
-        //Wait for user to press and release sw2
-        blockOnSwitch2();
+        while (sw2 == RELEASED) {};
+        wait(0.2);
+        while (sw2 == PRESSED) {};    
+        green_led = !green_led;
+        wait(0.2);
+
+        yellow_led = !yellow_led;
+        wait(0.5);
 
         //Flash the yellow
         yellow_led = !yellow_led;
@@ -43,33 +48,3 @@
     };
 }
 
-
-//Thread 1  - polling sw1 and controlling the red LED
-void blockOnSwitch1()
-{
-    //Spin on sw1
-    while (sw1 == RELEASED) {};
-    //Allow short delay for switch bounce
-    wait(0.2);
-    //Spin again on sw1
-    while (sw1 == PRESSED) {};    
-    //Toggle LED
-    red_led = !red_led;
-    //Again, wait for switch bounce
-    wait(0.2);
-}
-
-//Thread 2  - polling sw2 and controlling the green LED
-void blockOnSwitch2()
-{
-    //Spin on sw2
-    while (sw2 == RELEASED) {};
-    //Allow short delay for switch bounce
-    wait(0.2);
-    //Spin again on sw2
-    while (sw2 == PRESSED) {};    
-    //Toggle LED
-    green_led = !green_led;
-    //Again, wait for switch bounce
-    wait(0.2);  
-}