assignment

Dependencies:   mbed

Committer:
nyakuri
Date:
Sun Nov 01 10:16:54 2020 +0000
Revision:
2:fbcf17529c1a
Parent:
1:d5bb191dfa70
final codes for assignment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyakuri 0:9db31846895a 1 #include "mbed.h"
nyakuri 0:9db31846895a 2 DigitalOut trafficYellowlight(p5);
nyakuri 2:fbcf17529c1a 3 DigitalOut trafficRedlight(p7);
nyakuri 0:9db31846895a 4 DigitalIn pedestrainButton(p6);
nyakuri 0:9db31846895a 5 int main() {
nyakuri 0:9db31846895a 6 trafficYellowlight=1;
nyakuri 2:fbcf17529c1a 7 trafficRedlight=0;
nyakuri 0:9db31846895a 8 while(1)
nyakuri 0:9db31846895a 9 {
nyakuri 0:9db31846895a 10 if(pedestrainButton&trafficYellowlight){
nyakuri 0:9db31846895a 11 int counter=0;
nyakuri 0:9db31846895a 12 printf("counter is now%d\n",counter);
nyakuri 0:9db31846895a 13 // blink for 5 seconds
nyakuri 0:9db31846895a 14 while(counter<10){
nyakuri 0:9db31846895a 15 counter+=1;
nyakuri 0:9db31846895a 16 trafficYellowlight=!trafficYellowlight;
nyakuri 0:9db31846895a 17 wait_ms(500);//delay of 1 second
nyakuri 0:9db31846895a 18 }
nyakuri 0:9db31846895a 19 trafficYellowlight=0;//switch off
nyakuri 2:fbcf17529c1a 20 trafficRedlight=1;
nyakuri 0:9db31846895a 21 }
nyakuri 0:9db31846895a 22 if(!trafficYellowlight){
nyakuri 0:9db31846895a 23 trafficYellowlight=!pedestrainButton;
nyakuri 2:fbcf17529c1a 24 trafficRedlight=!trafficYellowlight;
nyakuri 0:9db31846895a 25 }
nyakuri 0:9db31846895a 26
nyakuri 0:9db31846895a 27 wait_ms(500);
nyakuri 0:9db31846895a 28 }
nyakuri 0:9db31846895a 29 }