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 0:be92c52fcd8c, committed 2019-11-28
- Comitter:
- vrasmusen
- Date:
- Thu Nov 28 15:57:16 2019 +0000
- Commit message:
- Project code 5
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Nov 28 15:57:16 2019 +0000
@@ -0,0 +1,105 @@
+#include "mbed.h"
+
+DigitalOut g1(p24); //green lights 1 and 3 use output pin 24
+DigitalOut g2(p25); //green lights 2 and 4 use output pin 25
+DigitalOut y1(p27); //yellow lights 1 and 3 use output pin 27
+DigitalOut y2(p28); //yellow lights 2 and 4 use output pin 28
+DigitalOut r1(p29); //red lights 1 and 3 use output pin 29
+DigitalOut r2(p30); //red lights 2 and 4 use output pin 30
+DigitalIn switchstate (p17); //switches 1 and 3 use input pin 17
+
+int main() {
+r1=r2=1;
+int state = 0;
+ while(1) {
+ if (switchstate.read() == 1)
+ state=1;
+
+ if (g1==1 || y1==1 && state==1) {
+ wait (1);
+ g1=0;
+ y1=1;
+ wait(1);
+ y1=0;
+ r1=r2=1;
+ wait(5);
+ }
+ else if (g2==1 || y2==1 && state==1) {
+ wait(1);
+ g2=0;
+ y2=1;
+ wait(1);
+ y2=0;
+ r2=r1=1;
+ wait(5);
+ }
+ else {
+ y1 = 1; //yellow 1 and 3 turn on
+ wait(0.5); //wait 1s
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5);
+ r1 = y1 = 0; //red and yellow 1 and 3 turn off
+ g1 = 1; //green turns on
+ wait(0.5); //wait 3s
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5);
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5);
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5);
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5);
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5);
+ g1 = 0; //green 1 and 3 turn off
+ y1 = 1; //yellow 1 and 3 turn on
+ wait(0.5); //wait 1s
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5); //wait 1
+ y1 = 0; //yellow 1 and 3 turn off
+ r1 = 1; //red 1 and 3 turn on
+ wait(0.5); //wait 1s
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5); //wait 1s
+ y2 = 1; //yellow 2 and 4 turn on
+ wait(0.5); //wait 1s
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5); //wait 1s
+ r2 = y2 = 0; //red and yellow 2 and 4 turn off
+ g2 = 1; //green 2 and 4 turn on
+ wait(0.5); //wait 3s
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5);
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5);
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5);
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5);
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5); //wait 3s
+ g2 = 0; //green 2 and 4 turn off
+ y2 = 1; //yellow 2 and 4 turn on
+ wait(0.5); //wait 1s
+ if (switchstate.read() == 1)
+ state=1;
+ wait(0.5); //wait 1s
+ y2 = 0; //yellow 2 and 4 turn off
+ r2 = 1; //red 2 and 4 turn on
+ }
+ }
+ }
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Nov 28 15:57:16 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file