UoD_ME21001_Group_1_12 / Mbed 2 deprecated 00beep

Dependencies:   mbed

Files at this revision

API Documentation at this revision

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 ();