Simple traffic light phase simulation

Dependencies:   mbed

main.cpp

Committer:
daklowprofile
Date:
2018-07-02
Revision:
0:401494462563

File content as of revision 0:401494462563:

#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();
    }
}