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.
Dependencies: mbed
Revision 2:837e1af33ebd, committed 2019-11-05
- Comitter:
- jfair
- Date:
- Tue Nov 05 15:14:42 2019 +0000
- Parent:
- 1:7b7576c83317
- Commit message:
- ta dah
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Nov 05 14:09:38 2019 +0000 +++ b/main.cpp Tue Nov 05 15:14:42 2019 +0000 @@ -12,7 +12,6 @@ void flag1() { if(button.read()) { cross = 0; - wait (0.5); } } void crossing() { @@ -31,45 +30,74 @@ //no wait should be required here as the normal lights function begins with a red light, this also minimises disruption void lightsa() { //creates the function for the first lights sequence - ra = 1; //turns on red light at same time - rb = 1; + for (int i=0; i<25; i++) { + ra = 1; + flag1 (); + wait (0.1); + } + for (int i=0; i<5; i++) { + ya = 1; flag1(); - wait(2.5);//waits 2.5 seconds - ya = 1; //turns the yellow light on - flag1(); - wait(0.5);//waits 0.5 seconds + wait (0.1); + } + for (int i=0; i<25; i++) { ra = 0; //turns off red light ya = 0; //turns off yellow light at same time ga = 1; //turns on green light at the same time flag1(); - wait (2.5); //waits 2.5 seconds + wait (0.1); + } + for (int i=0; i<5; i++) { ga = 0; // turns off green ya = 1; // turns on yellow light at same time flag1(); //chechs for switch press - wait (0.5);//waits 0.5seconds before repeating + wait (0.1);//waits 0.5seconds before repeating + } + for (int i=0; i<1; i++) { ya = 0; //turns off yellow light ra = 1; //turns on red light - } + flag1(); + wait (0.1); + } +} void lightsb() { //creates the function for the second lights sequence - rb = 1; //turns on red light at same time - wait(10); //waits ten seconds - yb = 1; //turns the yellow light on - wait(2); //waits two seconds + for (int i=0; i<25; i++) { + rb = 1; + flag1 (); + wait (0.1); + } + for (int i=0; i<5; i++) { + yb = 1; + flag1(); + wait (0.1); + } + for (int i=0; i<25; i++) { rb = 0; //turns off red light yb = 0; //turns off yellow light at same time gb = 1; //turns on green light at the same time - wait (14); //waits fourteen seconds + flag1(); + wait (0.1); + } + for (int i=0; i<5; i++) { gb = 0; // turns off green yb = 1; // turns on yellow light at same time - wait (3); //waits three + flag1(); //chechs for switch press + wait (0.1);//waits 0.5seconds before repeating + } + for (int i=0; i<1; i++) { yb = 0; //turns off yellow light rb = 1; //turns on red light - } - + flag1(); + wait (0.1); + } +} int main() { + cross = 1; while(1) { //repeats indefinitely - if (cross == 1) { + if (cross == 1) { + rb = 1; lightsa(); //calls the function for the first lights sequence + lightsb(); } else { crossing ();