assignment

Dependencies:   mbed

main.cpp

Committer:
nyakuri
Date:
2020-11-01
Revision:
2:fbcf17529c1a
Parent:
1:d5bb191dfa70

File content as of revision 2:fbcf17529c1a:

#include "mbed.h"
DigitalOut trafficYellowlight(p5);
DigitalOut trafficRedlight(p7);
DigitalIn pedestrainButton(p6);
int main() {
    trafficYellowlight=1;
    trafficRedlight=0;
    while(1) 
    {
        if(pedestrainButton&trafficYellowlight){
            int counter=0;
            printf("counter is now%d\n",counter);
            // blink for 5 seconds
            while(counter<10){
                counter+=1;
                trafficYellowlight=!trafficYellowlight;
                wait_ms(500);//delay of 1 second
            }
            trafficYellowlight=0;//switch off
             trafficRedlight=1;
             }
             if(!trafficYellowlight){
                 trafficYellowlight=!pedestrainButton;
                 trafficRedlight=!trafficYellowlight;
             }
        
             wait_ms(500);
               }
}