Simple traffic light phase simulation

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
daklowprofile
Date:
Mon Jul 02 08:58:34 2018 +0000
Commit message:
simple 3 traffic light phase in 3 junctions. no interrupt. Location: University Malaya Gate PJ

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
diff -r 000000000000 -r 401494462563 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 02 08:58:34 2018 +0000
@@ -0,0 +1,92 @@
+#include "mbed.h"
+
+#define MAX_LEN 64
+
+//T1
+DigitalOut t1red(p5);
+DigitalOut t1yellow(p6);
+DigitalOut t1green(p7);
+//T2
+DigitalOut t2red(p11);
+DigitalOut t2yellow(p12);
+DigitalOut t2green(p13);
+//T3
+DigitalOut t3red(p18);
+DigitalOut t3yellow(p19);
+DigitalOut t3green(p20);
+
+//switch
+//DigitalIn switcht1(p28);
+DigitalIn switcht2(p29);
+DigitalIn switcht3(p30);
+
+
+
+void t1light(char a){
+    if (a == 'R'){
+        t1red = 1;
+        t1yellow = 0;
+        t1green = 0;
+    }else if(a == 'Y'){
+        t1red = 0;
+        t1yellow = 1;
+        t1green = 0;
+    }else if(a == 'G'){
+        t1red = 0;
+        t1yellow = 0;
+        t1green = 1;
+    }else{} 
+}
+
+void t2light(char a){
+    if (a == 'R'){
+        t2red = 1;
+        t2yellow = 0;
+        t2green = 0;
+    }else if(a == 'Y'){
+        t2red = 0;
+        t2yellow = 1;
+        t2green = 0;
+    }else if(a == 'G'){
+        t2red = 0;
+        t2yellow = 0;
+        t2green = 1;
+    }else{}
+}
+
+void t3light(char a){
+    if (a == 'R'){
+        t3red = 1;
+        t3yellow = 0;
+        t3green = 0;
+    }else if(a == 'Y'){
+        t3red = 0;
+        t3yellow = 1;
+        t3green = 0;
+    }else if(a == 'G'){
+        t3red = 0;
+        t3yellow = 0;
+        t3green = 1;
+    }else{}
+}
+
+void traffic_default (char t1, char t2, char t3, int time){
+    t1light(t1);
+    t2light(t2);
+    t3light(t3);
+    wait(time);
+    }
+void normal_traffic(){
+    traffic_default('G','R','R',47);
+    traffic_default('Y','R','R',3);
+    traffic_default('R','G','R',38);
+    traffic_default('R','Y','R',3);
+    traffic_default('R','R','G',70);
+    traffic_default('R','R','Y',3);
+    }
+
+int main() {
+    while(1){
+    normal_traffic();
+    }
+}
diff -r 000000000000 -r 401494462563 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jul 02 08:58:34 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file