UoD_ME21001_Group_1_16 / Mbed 2 deprecated 4_project

Dependencies:   mbed

main.cpp

Committer:
vrasmusen
Date:
2019-11-28
Revision:
0:4d589ddb43db

File content as of revision 0:4d589ddb43db:

//********************************************************************* //
// 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;
        }
    }
}