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@4:21c7f1725060, 2020-11-01 (annotated)
- Committer:
- harerimana
- Date:
- Sun Nov 01 13:26:46 2020 +0000
- Revision:
- 4:21c7f1725060
- Parent:
- 3:b1c994da96f5
- Child:
- 5:e1afaceb1196
Add a RED light and initialise its state to OFF.
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 | 4:21c7f1725060 | 20 | |
| harerimana | 2:602c96685466 | 21 | } | 
| harerimana | 2:602c96685466 | 22 | if(!trafficYellowlight){ | 
| harerimana | 4:21c7f1725060 | 23 | trafficYellowlight=!pedestrainButton; // yellow and red lights are switched opposetely | 
| harerimana | 4:21c7f1725060 | 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 | 4:21c7f1725060 | 29 | } |