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.
Revision 0:4e4284443cd3, committed 2018-11-15
- Comitter:
- jennifersouthern
- Date:
- Thu Nov 15 16:01:35 2018 +0000
- Commit message:
- .
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 15 16:01:35 2018 +0000
@@ -0,0 +1,108 @@
+/****************************************************************************/
+//ME21001 Project
+//Group 1,3
+//Code for a traffic intersection, four way junction with pedestrian crossings
+//LDRs used to sense 'cars'
+//switches used for pedestrian crossings
+/*****************************************************************************/
+
+
+#include "mbed.h"
+
+DigitalOut Green(p25);
+DigitalOut Yellow(p24);
+DigitalOut Red(p23);
+DigitalIn sensor(p22);
+DigitalIn button(p21);
+
+int main() {
+
+bool buttonpressed = 0;
+bool sensorsensed = 0;
+ while (1){
+
+
+while (sensorsensed ==0){
+
+ for (int t=0; t<30;t++){
+ Red=1;
+ Green=Yellow=0;
+
+ if (button.read())
+ buttonpressed=1;
+ wait(0.1);
+
+ if (sensor.read())
+ sensorsensed=1;
+ wait(0.1);
+ }
+
+ for (int t=0; t<10;t++){
+ Red=Yellow=1;
+ Green=0;
+
+ if (button.read())
+ buttonpressed=1;
+ wait(0.1);
+
+ if (sensor.read())
+ sensorsensed=1;
+ wait(0.1);
+ }
+
+ for (int t=0; t<30;t++){
+ Red=Yellow=0;
+ Green=1;
+
+ if (button.read())
+ buttonpressed=1;
+ wait(0.1);
+
+ if (sensor.read())
+ sensorsensed=1;
+ wait(0.1);
+ }
+
+ for (int t=0; t<10;t++){
+ Red=Green=0;
+ Yellow=1;
+
+ if (button.read())
+ buttonpressed=1;
+ wait(0.1);
+
+ if (sensor.read())
+ sensorsensed=1;
+ wait(0.1);
+ }
+
+ for (int t=0; t<30;t++){
+ Red=1;
+ Green=Yellow=0;
+
+ if (button.read())
+ buttonpressed=1;
+ wait(0.1);
+
+ if (sensor.read())
+ sensorsensed=1;
+ wait(0.1);
+ }
+
+ if (buttonpressed == 1){
+ Red =1;
+ wait(5);
+ buttonpressed = 0;
+ }
+ }
+ }
+
+ Red = 1;
+ if (sensor.read(0))
+ sensorsensed = 0;
+
+
+
+ }
+ }
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Nov 15 16:01:35 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187 \ No newline at end of file