UoD_ME21001_Group_1_07 / Mbed 2 deprecated Project_Test_9

Dependencies:   mbed

main.cpp

Committer:
callumhoffie
Date:
2019-11-21
Revision:
0:67f1965f904d
Child:
1:fb4ff3d2b5d0

File content as of revision 0:67f1965f904d:

 //Amalgamation of Project_Test_1 and Project_Test_2_switch codes to check viability of a simple 1/2 switch light interface.
 //Expansion of Project_Test_1 protocol to include three more pins and two more traffic light circuits.



#include "mbed.h"
DigitalOut red1(p21);           //Assign digital output value of red1 to mbed pin p21
DigitalOut yellow1(p22);        //Assign digital output value of yellow1 to mbed pin p22
DigitalOut green1(p23);         //Assign digital output value of green1 to mbed pin p23
DigitalOut red2(p24);           //Assign digital output value of red2 to mbed pin p24
DigitalOut yellow2(p25);        //Assign digital output value of yellow2 to mbed pin p25
DigitalOut green2(p27);         //Assign digital output value of green2 to mbed pin p26
DigitalIn switchInput(p15);

            
int main() {         
    int x = 0;
    while(1) {                  //Repeat indefinitely
         // read the input state only once in the while loop
        if(switchInput.read() == 0) {
            red1 = 1;               //Turn on red1
            red2 = 1;               //Turn on red2
            wait(3);                //Wait 3 seconds
            if(switchInput.read() == 1){
                x = 1;
                }
            yellow1 = 1;            //Turn on yellow1
            wait(1);                //Wait 1 second
            if(switchInput.read() == 1){
                x = 1;
                }
            red1 = 0;               //Turn off red1
            yellow1 = 0;            //Turn off yellow1
            green1 = 1;             //Turn on green1        
            wait(3);                //Wait 3 seconds
            if(switchInput.read() == 1){
                x = 1;
                }
            green1 = 0;             //Turn off green1
            yellow1 = 1;            //Turn on yellow1
            wait(1);                //Wait 1 second
            if(switchInput.read() == 1){
                x = 1;
                }
            yellow1 = 0;            //Turn off yellow1
            red1 = 1;               //Turn on red1
            wait(3);                //Wait 3 seconds
            if(switchInput.read() == 1){
                x = 1;
                }
            yellow2 = 1;            //Turn on yellow2
            wait(1);                //Wait 1 second
            if(switchInput.read() == 1){
                x = 1;
                }
            red2 = 0;               //Turn off red2
            yellow2=0;              //Turn off yellow2
            green2=1;               //Turn on green2
            wait(3);                //Wait 3 seconds
            if(switchInput.read() == 1){
                x = 1;
                }
            green2 = 0;             //Turn off green2
            yellow2=1;              //Turn on yellow2
            wait(1);                //Wait 1 second
            if(switchInput.read() == 1){
                x = 1;
                }
            yellow2=0;              //Turn off yellow2
            if(x == 1) {
             red1 = 1;
             red2 = 1;
             yellow1 = 0;
             yellow2 = 0;
             green1= 0;
             green2 = 0;
             wait(10);
             x = 0;
             }
             }
    }
}                               //End of statement