UoD_ME21001_Group_1_16 / Mbed 2 deprecated 5_project

Dependencies:   mbed

main.cpp

Committer:
vrasmusen
Date:
2019-11-28
Revision:
0:be92c52fcd8c

File content as of revision 0:be92c52fcd8c:

#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 1 and 3 use input pin 17
 
int main()  {
r1=r2=1;
int state = 0;
    while(1)    {
        if (switchstate.read() == 1)
            state=1;

            if (g1==1 || y1==1 && state==1) {
                wait (1);
                g1=0;
                y1=1;
                wait(1);
                y1=0;
                r1=r2=1;
                wait(5);
            }
            else if (g2==1 || y2==1 && state==1) {
                wait(1);
                g2=0;
                y2=1;
                wait(1);
                y2=0;
                r2=r1=1;
                wait(5);
            }
            else {
                y1 = 1;                //yellow 1 and 3 turn on
            wait(0.5);                //wait 1s
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);
                r1 = y1 = 0;          //red and yellow 1 and 3 turn off
                g1 = 1;                //green turns on
            wait(0.5);                //wait 3s
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);
                g1 = 0;                //green 1 and 3 turn off
                y1 = 1;                //yellow 1 and 3 turn on
            wait(0.5);                //wait 1s
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);               //wait 1
                y1 = 0;                //yellow 1 and 3 turn off
                r1 = 1;                //red 1 and 3 turn on
            wait(0.5);                //wait 1s
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);                //wait 1s
                y2 = 1;                //yellow 2 and 4 turn on
            wait(0.5);                //wait 1s
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);               //wait 1s
                r2 = y2 = 0;          //red and yellow 2 and 4 turn off
                g2 = 1;                //green 2 and 4 turn on
            wait(0.5);                //wait 3s
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);                //wait 3s
                g2 = 0;                //green 2 and 4 turn off
                y2 = 1;                //yellow 2 and 4 turn on 
            wait(0.5);                //wait 1s
            if (switchstate.read() == 1)
            state=1;
            wait(0.5);               //wait 1s
                y2 = 0;                //yellow 2 and 4 turn off
                r2 = 1;                //red 2 and 4 turn on
            }
        }   
    }