Jeff Nguyen / Mbed 2 deprecated Traffic_Light

Dependencies:   mbed

Revision:
1:992086cb4c27
Parent:
0:41f066ce55cf
Child:
2:37d5e9d92b66
diff -r 41f066ce55cf -r 992086cb4c27 main.cpp
--- a/main.cpp	Sat Oct 20 20:24:53 2018 +0000
+++ b/main.cpp	Sat Oct 20 21:58:52 2018 +0000
@@ -25,6 +25,7 @@
     pedest = true;
     Onboard = 1;
 }
+
 void reset()
 {//start reset procedure.
   //Declaring a procedure named reset, 0 arguments are passed.
@@ -37,12 +38,25 @@
   //All Lights are switched off. (Procedure Ends return to main)
 }//End reset procedure.
 
+void safe()
+{   
+    if (unsafe == false)
+    {
+        unsafe = true;
+        reset();
+    }
+    else if(unsafe == true)
+    {
+        unsafe = false;
+        reset();
+    }
+}
 
 void sequence(int unsafe)
 // Declaring a procedure for sequence. 2 Arguments are recieved - unsafe and pedestrians
 {//Start sequence procedure. 
     if(unsafe == true)
-    {
+    {   
     //  Sequence          TRAFFIC 1, TRAFFIC 2
         RLED = 1;  //     RED ON     RED OFF                
         GGLED = 1; //     AMBER OFF  AMBER OFF 
@@ -65,9 +79,10 @@
         AALED = 1; //     GREEN OFF   GREEN OFF
         wait(2);   
     //----------------------------------------------
-        RRLED = 0; //     RED OFF     RED OFF
-        ALED = 0;  //     AMBER OFF   AMBER OFF
-        AALED = 0;  //     GREEN OFF   GREEN OFF     ----------> The same as reset I may replace this with a call to reset
+        reset();          /*RRLED = 0; //    RED OFF     RED OFF
+                          ALED = 0;   //     AMBER OFF   AMBER OFF
+                          AALED = 0;  //     GREEN OFF   GREEN OFF
+                            This sequence is the same as reset()*/
     }
     else if(unsafe == false)
     {
@@ -105,10 +120,10 @@
                 while(counter <= 20);// condition of counter is while the counter is less than or equal to 10
         }        
     //----------------------------------------------
-        GLED = 0;  //     RED OFF     RED OFF
-                 //     AMBER ON    AMBER ON
-        ALED = 1; //     GREEN OFF   GREEN OFF
-        wait(2);   
+        GLED = 0; //     RED OFF     RED OFF
+        ALED = 1; //     AMBER ON    AMBER ON
+        wait(2);  //     GREEN OFF   GREEN OFF
+          
     //----------------------------------------------
         RRLED = 1; //     RED OFF     RED ON 
         RLED = 0;
@@ -131,13 +146,14 @@
 int main()
 {//start main function.
     //Main procedure, I will create a loop and initalise my variables
-    bool unsafe = false; 
     /*To create my sequence Ivneed my lights to start on the same lights everytime.
     Therefore I will create a reset which will set all of the lights off.
     I will do this by creating a separate procedure for my main procedure to point to.*/
     
     reset();//Main points to reset procedure
-    button.fall(&pedestrians); // This fall procedure in is the button interrupt class 
+    //button.fall(&pedestrians); // This fall procedure in is the button interrupt class
+    Switch.fall(&safe);
+    button.fall(&pedestrians);
     while(1)
     {//Start of while