All tasks complete

Dependencies:   mbed MCP23017 mbed-rtos WattBob_TextLCD

Revision:
13:822b0e56ea68
Parent:
12:f4052a23ddc7
Child:
14:25241ed5b056
Child:
17:6b4d94f9c77a
diff -r f4052a23ddc7 -r 822b0e56ea68 assignment3tasks.cpp
--- a/assignment3tasks.cpp	Wed Mar 27 15:14:10 2019 +0000
+++ b/assignment3tasks.cpp	Wed Mar 27 16:05:51 2019 +0000
@@ -18,8 +18,8 @@
 
 //indicators 
 DigitalOut          ngeneind(pin_LED1);
-PwmOut          leftind(pin_LED2); //was digitalout
-PwmOut          rightind(pin_LED3);//was digitalout
+DigitalOut          leftind(pin_LED2); //was digitalout
+DigitalOut         rightind(pin_LED3);//was digitalout
 DigitalOut          sideind(pin_LED4);
 
 
@@ -250,10 +250,11 @@
 
 void task9indLED()
 {
+    int count = 0;
     while(true){
         
        
-        int turnleft = leftsw;
+    /*    int turnleft = leftsw;
         int turnright = rightsw;
         
         
@@ -273,9 +274,9 @@
         float left_period = 1.0;
         float right_period = 1.0;
         float left_pulswidth = 0.0;
-        float right_pulswidth = 0.0;
+        float right_pulswidth = 0.0;*/
 
-        if (turnleft != 0)
+        /*if (turnleft != 0)
         {
             left_period = (1/TASKFREQ9);
             left_pulswidth = (1/(2*TASKFREQ9)); 
@@ -298,21 +299,47 @@
         leftind.pulsewidth(left_pulswidth);
         rightind.period(right_period);
         rightind.pulsewidth(right_pulswidth);
+        */
         
         
        
-       float delay = 1000 / TASKFREQ9S2;
-       Thread::wait((int)delay);
+       //float delay = 1000 / TASKFREQ9S2;
+       //Thread::wait((int)delay);
+       
+       // Counter ensure everything works off of 2Hz loop
+       count++;
+       leftind = leftsw;
+       rightind = rightsw;
+       
+       if (leftsw == 1 && rightsw == 1){
+        carstateXS.lock();
+        leftind = 0;
+        rightind = 0; // current issue :just stopping here 
+        carstateXS.unlock();
+        }
+        if (count == 2||count == 4){ // flash indicators every second
+                    carstateXS.lock();
+               if (leftind == 1 && rightind == 0){
+                leftind = 0;
+                    }
+        else if (rightind == 1 && leftind == 0){
+                rightind = 0;
+                    }
         
-        
+        else if (leftind == 0 && rightind == 0){
+                    }
+                    carstateXS.unlock();
+        }
+        if (count == 4){ // send data every 2 seconds
+            count = 0;
+        }
+        Thread::wait(500);
         
         }
 
-
+}
 
 
-}       
-
 void taskXserialdump()
 {
     while(true)