Reverse Parking sensor

Dependencies:   N5110 SRF02 buzzer mbed

Files at this revision

API Documentation at this revision

Comitter:
Reniboy
Date:
Thu May 05 14:17:42 2016 +0000
Parent:
1:775f6e8071a2
Commit message:
parking

Changed in this revision

buzzer.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/buzzer.lib	Thu May 05 02:08:46 2016 +0000
+++ b/buzzer.lib	Thu May 05 14:17:42 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/Reniboy/code/buzzer/#01eac446ef9f
+https://developer.mbed.org/users/Reniboy/code/buzzer/#622b1d533a1c
--- a/main.cpp	Thu May 05 02:08:46 2016 +0000
+++ b/main.cpp	Thu May 05 14:17:42 2016 +0000
@@ -22,7 +22,7 @@
     lcd.clear();
     lcd.refresh();
     r_led = 1;
-    sw2.mode(PullNone);
+    sw2.mode(PullNone); // Set pullup button 
     sw2.fall(&sw2_isr);
     sw3.mode(PullNone);
     sw3.fall(&sw3_isr);
@@ -33,6 +33,8 @@
 
 void mainProg()
 {
+    sw2.mode(PullNone);
+    sw2.fall(&sw2_isr);
 
 
     while(1) {
@@ -43,10 +45,10 @@
             if (g_sw2_flag) {
                 g_sw2_flag = 0; //clear the flag
                 buzzer.beep(1700,0.2);//make sound when sw2 is pressed
-                activeIn();
+                active();
                 beeping();//This function is called to vary the speaker with the distance for each subsequent function
             }
-            sleep();
+            
         }
 
         if (ain < 0.7 && ain > 0.3) {
@@ -58,17 +60,19 @@
                 beeping();
 
             }
-            sleep();
+            
         }
         if (ain > 0.7) {
             classicMode1();
             if (g_sw2_flag) {
                 g_sw2_flag = 0; //clear the flag
                 buzzer.beep(1700,0.2); //make sound when selection is chosen
+                activeIn();
                 beeping();
+                
             }
 
-            sleep();
+        
         }
     }
 
@@ -161,6 +165,7 @@
     lcd.drawCircle(42,47,14,0);
     lcd.drawCircle(42,47,2,0);
     lcd.printString(str,1,0);
+    lcd.printString("cm",12,0);
 
     lcd.drawLine(0,47,83,47,1);//centre line
     lcd.refresh();
@@ -179,6 +184,7 @@
     lcd.drawCircle(42,47,2,0);
     lcd.drawLine(0,47,83,47,1);//centre line
     lcd.printString(str,1,0);
+    lcd.printString("cm",12,0);
     lcd.refresh();
 
 }
@@ -196,6 +202,7 @@
     lcd.drawCircle(42,47,2,0);
     lcd.drawLine(0,47,83,47,1);//centre line
     lcd.printString(str,1,0);
+   lcd.printString("cm",12,0);
 
     lcd.refresh();
 }
@@ -213,6 +220,7 @@
     lcd.drawCircle(42,47,2,0);
     lcd.drawLine(0,47,83,47,1);//centre line
     lcd.printString(str,1,0);
+    lcd.printString("cm",12,0);
 
     lcd.refresh();
 
@@ -231,6 +239,8 @@
     lcd.drawCircle(42,47,2,0);
     lcd.drawLine(0,47,83,47,1);//centre line
     lcd.printString(str,1,0);
+    lcd.printString("cm",12,0);
+    
 
     lcd.refresh();
 }
@@ -247,6 +257,7 @@
     lcd.drawCircle(42,47,14,0);
     lcd.drawCircle(42,47,2,0);
     lcd.printString(str,1,0);
+    lcd.printString("cm",12,0);
 
     lcd.refresh();
 
@@ -264,6 +275,7 @@
     lcd.drawCircle(42,47,14,0);
     lcd.drawCircle(42,47,2,0);
     lcd.printString(str,1,0);
+    lcd.printString("cm",12,0);
     lcd.refresh();
 }
 
@@ -280,6 +292,7 @@
     lcd.drawCircle(42,47,14,0);
     lcd.drawCircle(42,47,2,0);
     lcd.printString(str,1,0);
+    lcd.printString("cm",12,0);
     lcd.refresh();
 }
 
@@ -295,6 +308,7 @@
     lcd.drawCircle(42,47,26,0);
     lcd.drawCircle(42,47,14,0);
     lcd.printString(str,1,0);
+    lcd.printString("cm",12,0);
 
     lcd.refresh();
 }
@@ -313,6 +327,7 @@
     lcd.drawLine(42,47,80,36,1);//Fourth trace to the right
     lcd.drawLine(0,47,83,47,1);//centre line
     lcd.printString(str,1,0);
+    lcd.printString("cm",12,0);
     lcd.refresh();
 }
 
@@ -330,6 +345,7 @@
         lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left
         lcd.drawRect(78.5,19,4.5,12,1);
         lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right
+        lcd.printString("cm",46,2.5);
         lcd.refresh();
     }
     if (distance<=250) {
@@ -339,6 +355,7 @@
         lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left
         lcd.drawRect(78.5,19,4.5,12,1);
         lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right
+        lcd.printString("cm",46,2.5);
         lcd.refresh();
     }
     if (distance< 100) {
@@ -350,6 +367,7 @@
         lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left
         lcd.drawRect(78.5,19,4.5,12,1);
         lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right
+        lcd.printString("cm",46,2.5);
         lcd.refresh();
 
     }
@@ -364,6 +382,7 @@
         lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left
         lcd.drawRect(78.5,19,4.5,12,1);
         lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right
+        lcd.printString("cm",46,2.5);
         lcd.refresh();
 
 
@@ -383,6 +402,7 @@
         lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left
         lcd.drawRect(78.5,19,4.5,12,1);
         lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right
+        lcd.printString("cm",46,2.5);
         lcd.refresh();
     }
 
@@ -403,6 +423,7 @@
         lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left
         lcd.drawRect(78.5,19,4.5,12,1);
         lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right
+        lcd.printString("in",46,2.5);
         lcd.refresh();
     }
     if (distance<=250) {
@@ -412,6 +433,7 @@
         lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left
         lcd.drawRect(78.5,19,4.5,12,1);
         lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right
+        lcd.printString("in",46,2.5);
         lcd.refresh();
     }
     if (distance< 100) {
@@ -423,6 +445,7 @@
         lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left
         lcd.drawRect(78.5,19,4.5,12,1);
         lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right
+        lcd.printString("in",46,2.5);
         lcd.refresh();
 
     }
@@ -437,6 +460,7 @@
         lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left
         lcd.drawRect(78.5,19,4.5,12,1);
         lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right
+        lcd.printString("in",46,2.5);
         lcd.refresh();
 
 
@@ -456,6 +480,7 @@
         lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left
         lcd.drawRect(78.5,19,4.5,12,1);
         lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right
+        lcd.printString("in",46,2.5);
         lcd.refresh();
     }
 
@@ -476,15 +501,15 @@
 
 
     if (distance>250.0)  {
-        t = 1.5;
+        t = 0.6;
 
     }
     if (distance<=200.0) {
-        t = 1.2;
+        t = 0.5;
 
     }
     if (distance<100.0) {
-        t = 1;
+        t = 0.4;
 
 
     }
@@ -494,17 +519,17 @@
 
     }
     if (distance<60) {
-        t = 0.6;
+        t = 0.2;
 
 
     }
     if (distance<40) {
-        t = 0.4;
+        t = 0.1;
         lcd.printString(str,1,0);
 
     }
     if (distance<20) {
-        t = 0.3;
+        t = 0.05;
         lcd.printString(str,1,0);
     }
 
@@ -556,6 +581,8 @@
 void active() //Function containing the parking sensor measurements in cm
 
 {
+    sw3.mode(PullNone);
+    sw3.fall(&sw3_isr);
     lcd.clear();
     ticker.attach(&timer_isr,1); //Ticker is attached to call function at specified rate of evry 0.5 seconds
     while (1) {
@@ -581,11 +608,13 @@
 void activeIn() //Function containing the implementation of the parking sensor function in inches
 
 {
+     sw3.mode(PullNone);
+    sw3.fall(&sw3_isr);
     lcd.clear();
     ticker3.attach(&timer_isr,1);
     while (1) {
         if (g_timer_flag) {
-            g_timer_flag = 0;
+            g_timer_flag = 0; //if it has, clear the flag
             sensingImageIn();
             lcd.refresh();
             beeping();
@@ -606,6 +635,8 @@
 
 void radar()
 {
+    sw3.mode(PullNone);
+    sw3.fall(&sw3_isr);
     lcd.clear();
     ticker2.attach(&timer_isr,0.5); //Sets another interrupt based system where the function is called periodically.
     while(1) {
@@ -678,9 +709,9 @@
 {
     lcd.clear();
     lcd.printString("SELECT A MODE:",0,0.5);
-    lcd.printString("CLASSIC MODE (cm)", 11,2);
+    lcd.printString("CLASSIC (cm)", 11,2);
     lcd.printString("RADAR MODE",11,3);
-    lcd.printString("CLASSIC MODE (in)",11,4);
+    lcd.printString("CLASSIC (in)",11,4);
     lcd.drawCircle(3,34.5,3,1);
     lcd.refresh();
 }