Mirembe Jean d'Amour / Mbed 2 deprecated ASSIGNMENT_CODES

Dependencies:   mbed

Committer:
titig
Date:
Sun Nov 01 12:28:58 2020 +0000
Revision:
4:232f69c6c92c
Parent:
3:a1263051d681
Child:
5:0225e0fdab62
Add a RED light and initialise its state to OFF

Who changed what in which revision?

UserRevisionLine numberNew contents of line
titig 0:c7ce501d534b 1 #include "mbed.h"
titig 4:232f69c6c92c 2 DigitalOut trafficYellowlight(p5); //Yellow light pin declaration
titig 4:232f69c6c92c 3 DigitalIn pedestrainButton(p8); //Switch button pin declaration
titig 4:232f69c6c92c 4 DigitalOut trafficRedlight(p10); //Red light pin declaration
titig 0:c7ce501d534b 5 int main() {
titig 4:232f69c6c92c 6 trafficYellowlight=1; //Initialize Yellow light to ON
titig 4:232f69c6c92c 7 trafficRedlight=0; //Initialize Red light to OFF
titig 0:c7ce501d534b 8 while(1)
titig 0:c7ce501d534b 9 {
titig 0:c7ce501d534b 10
titig 2:a98660025857 11 if(pedestrainButton & trafficYellowlight){
titig 4:232f69c6c92c 12 int counter=0; // declaration and initialization of counter
titig 2:a98660025857 13 while(counter<10){
titig 2:a98660025857 14 counter+=1;
titig 4:232f69c6c92c 15 trafficYellowlight=!trafficYellowlight; //Blinking Yellow light for 10 second
titig 4:232f69c6c92c 16 wait_ms(500); //delay of 5 second
titig 2:a98660025857 17 }
titig 4:232f69c6c92c 18 trafficYellowlight=0; //switch off yellow light
titig 2:a98660025857 19 }
titig 2:a98660025857 20 if(!trafficYellowlight){
titig 4:232f69c6c92c 21 trafficYellowlight=!pedestrainButton; // Yellow light reamin switched OFF but once button is pressed to be OFF Yellow light will be ON
titig 2:a98660025857 22 }
titig 2:a98660025857 23
titig 2:a98660025857 24 wait_ms(500);
titig 0:c7ce501d534b 25 }
titig 2:a98660025857 26 }