UoD_ME21001_Group_1_12 / Mbed 2 deprecated 0fullfunctionlights

Dependencies:   mbed

Revision:
1:7b7576c83317
Parent:
0:47a0c4ac5a0f
Child:
2:837e1af33ebd
--- a/main.cpp	Tue Oct 29 16:45:51 2019 +0000
+++ b/main.cpp	Tue Nov 05 14:09:38 2019 +0000
@@ -9,6 +9,12 @@
 
 bool cross;
 
+void flag1() {
+    if(button.read()) {
+        cross = 0;
+        wait (0.5);
+    }
+}
 void crossing() {
     ra = 1;//simultainiously turns on red lights to allow crossing 
     rb = 1;
@@ -18,7 +24,7 @@
     wait (1);//r
     ga = 1;//r
     wait (1);//r
-    ga = 1;//r
+    ga = 0;//r
     cross = 1;//sets value of crossing request to false to prevent looping 
     wait (1);//remove later for testing
     }   
@@ -26,17 +32,23 @@
 
 void lightsa() { //creates the function for the first lights sequence 
          ra = 1; //turns on red light at same time
-         wait(3); //waits ten seconds
+         rb = 1;
+         flag1();
+         wait(2.5);//waits 2.5 seconds
          ya = 1; //turns the yellow light on 
-         wait(1); //waits two seconds
+         flag1();
+         wait(0.5);//waits 0.5 seconds
          ra = 0; //turns off red light
          ya = 0; //turns off yellow light at same time
          ga = 1; //turns on green light at the same time
-         wait (3); //waits fourteen seconds
+         flag1();
+         wait (2.5); //waits 2.5 seconds
          ga = 0; // turns off green 
          ya = 1; // turns on yellow light at same time
-         wait (1); //waits three seconds before repeating
-         ya = 0; //turns off yellow light 
+         flag1(); //chechs for switch press
+         wait (0.5);//waits 0.5seconds before repeating
+         ya = 0; //turns off yellow light
+         ra = 1; //turns on red light
     }
 void lightsb() { //creates the function for the second lights sequence 
          rb = 1; //turns on red light at same time
@@ -51,17 +63,13 @@
          yb = 1; // turns on yellow light at same time
          wait (3); //waits three  
          yb = 0; //turns off yellow light
+         rb = 1; //turns on red light
     }
     
 int main() {
     while(1) { //repeats indefinitely
-    if (button.read()) { 
-    cross = 0; 
-    } 
     if (cross == 1) { 
-        rb = 1; //keeps red light from second sequence on during sequence one 
         lightsa(); //calls the function for the first lights sequence
-        ra = 1; //keeps red light for sequence one on during sequence two
         }
     else {
         crossing ();