Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@5:e1afaceb1196, 2020-11-01 (annotated)
- Committer:
- harerimana
- Date:
- Sun Nov 01 13:30:39 2020 +0000
- Revision:
- 5:e1afaceb1196
- Parent:
- 4:21c7f1725060
- Child:
- 6:14626bbcb236
When the YELLOW light is completely OFF then switch ON the RED light
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
harerimana | 3:b1c994da96f5 | 1 | #include "mbed.h" |
harerimana | 3:b1c994da96f5 | 2 | DigitalOut trafficYellowlight(p7); |
harerimana | 4:21c7f1725060 | 3 | DigitalOut trafficRedlight(p9); |
harerimana | 1:18bf4c2c22ec | 4 | DigitalIn pedestrainButton(p8); |
harerimana | 0:392dea3408f2 | 5 | int main() { |
harerimana | 2:602c96685466 | 6 | trafficYellowlight=1; |
harerimana | 4:21c7f1725060 | 7 | trafficRedlight=0; |
harerimana | 0:392dea3408f2 | 8 | while(1) |
harerimana | 0:392dea3408f2 | 9 | { |
harerimana | 2:602c96685466 | 10 | if(pedestrainButton&trafficYellowlight){ |
harerimana | 2:602c96685466 | 11 | int counter=0; |
harerimana | 2:602c96685466 | 12 | printf("counter is now%d\n",counter); |
harerimana | 2:602c96685466 | 13 | // blink for 5 seconds |
harerimana | 2:602c96685466 | 14 | while(counter<10){ |
harerimana | 2:602c96685466 | 15 | counter+=1; |
harerimana | 2:602c96685466 | 16 | trafficYellowlight=!trafficYellowlight; |
harerimana | 3:b1c994da96f5 | 17 | wait_ms(5000);//delay of 5 second |
harerimana | 2:602c96685466 | 18 | } |
harerimana | 2:602c96685466 | 19 | trafficYellowlight=0;//switch off |
harerimana | 5:e1afaceb1196 | 20 | trafficRedlight=1; // set trafficReslight on |
harerimana | 2:602c96685466 | 21 | } |
harerimana | 2:602c96685466 | 22 | if(!trafficYellowlight){ |
harerimana | 5:e1afaceb1196 | 23 | trafficYellowlight=!pedestrainButton; // yellow and red lights are switched opposetely |
harerimana | 5:e1afaceb1196 | 24 | |
harerimana | 2:602c96685466 | 25 | } |
harerimana | 0:392dea3408f2 | 26 | |
harerimana | 4:21c7f1725060 | 27 | wait_ms(5000); // wait for 5 second |
harerimana | 0:392dea3408f2 | 28 | } |
harerimana | 5:e1afaceb1196 | 29 | } |
harerimana | 5:e1afaceb1196 | 30 | |
harerimana | 5:e1afaceb1196 | 31 |