UoD_ME21001_Group_1_16 / Mbed 2 deprecated 4_project

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
vrasmusen
Date:
Thu Nov 28 15:57:52 2019 +0000
Commit message:
Project code 4

Changed in this revision

main.cpp 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 28 15:57:52 2019 +0000
@@ -0,0 +1,66 @@
+//********************************************************************* //
+// this will cause the lights to flash in the UK Traffic light sequence //
+//              and allow pedestrians to cross                          //
+//********************************************************************* //
+ 
+#include "mbed.h"
+ 
+DigitalOut g1(p24);                //green lights 1 and 3 use output pin 24
+DigitalOut g2(p25);                //green lights 2 and 4 use output pin 25
+DigitalOut y1(p27);                //yellow lights 1 and 3 use output pin 27
+DigitalOut y2(p28);                //yellow lights 2 and 4 use output pin 28
+DigitalOut r1(p29);                //red lights 1 and 3 use output pin 29
+DigitalOut r2(p30);                //red lights 2 and 4 use output pin 30
+DigitalIn switchstate (p17);            //switches use input pin 17
+ 
+int main()
+{
+ 
+    g1=r2=1;          //1 set red, 1 set green (starting condition)
+ 
+    while(1) {
+        while (switch1.read()==1) {    //while buttons are not pressed  
+            if (g1 = 1) {       //runs normal traffic routine if set 1 starts green
+                wait(1);
+                y1=1;
+                g1=0;
+                wait(1);
+                y1=r2=0;
+                g2=1;
+            } else {
+                wait(1);        //runs normal traffic routine if set 2 green
+                y2=1;
+                g2=0;
+                wait(1);
+                y2=r1=0;
+                g1=0;
+            }
+        }
+        if (g1=1) {     //if set 1 green when button pressed, move to green, wait and start set 2
+            wait(1);
+            y1=1;
+            g1=0;
+            wait(1);
+            r1=1;
+            y1=0;
+            wait(5);
+            y2=0;
+            wait(1);
+            y2=0;
+            g2=1;
+        } else {        //same as above but set 2 was green
+            wait(1);
+            y2=1;
+            g2=0;
+            wait(1);
+            r1=1;
+            y2=0;
+            wait(5);
+            y1=0;
+            wait(1);
+            y1=0;
+            g1=1;
+        }
+    }
+}
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Nov 28 15:57:52 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file