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 1:bd2414fc0fdc, committed 2019-11-19
- Comitter:
- jfair
- Date:
- Tue Nov 19 16:29:10 2019 +0000
- Parent:
- 0:b8a0da291a83
- Commit message:
- beeper
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Nov 19 15:10:27 2019 +0000
+++ b/main.cpp Tue Nov 19 16:29:10 2019 +0000
@@ -8,6 +8,7 @@
DigitalIn buttona(p18); //defines the switch as a digital input
DigitalIn buttonb(p17);
DigitalOut led(LED1);
+DigitalOut spk(p28);
bool crossa;
bool crossb;
@@ -22,29 +23,24 @@
crossb = 0;
}
}
+void beep() {
+ spk = 1;
+ wait (0.01);
+ spk = 0;
+ }
+
void crossingfull() {
- ra = 1;//simultainiously turns on red lights to allow crossing
- rb = 1;
+ for (int i=0; i<100; i++) {
+ ra = 1;//simultainiously turns on red lights to allow crossing
+ rb = 1;
+ beep ();
+ }
led = 1;
crossa = 1;//sets value of crossing request to false to prevent looping
crossb = 1;
wait (1);//remove later for testing
led = 0;
- }
-void crossinga() {
- ra = 1;//turns on red lights to allow crossing
- led = 1;
- crossa = 1;//sets value of crossing request to false to prevent looping
- wait (1);//remove later for testing
- led = 0;
- }
-void crossingb() {
- rb = 1;
- led = 1;
- crossb = 1;//sets value of crossing request to false to prevent looping
- wait (1);//remove later for testing
- led = 0;
- }
+ }
//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
@@ -119,10 +115,10 @@
lightsb();
}
else if (crossa == 0 && crossb == 1) {
- crossinga ();
+ crossingfull ();
}
else if (crossa == 1 && crossb == 0) {
- crossingb ();
+ crossingfull ();
}
else if (crossa == 0 && crossb == 0) {
crossingfull ();