EMT 2410 | Project Wall-E A Radar Detection System Using the HCSR04 Ultrasonic Sensor for Object Detection and Text LCD to output distance and angle of a Servo Motor.

Dependencies:   Servo TextLCD mbed ultra

Revision:
0:faeefad8239f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/try.cpp	Fri May 18 01:13:36 2018 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h"
+#include "Servo.h"
+#include "TextLCD.h"
+#include "hcsr04.h"
+
+
+int angle (int);
+
+HCSR04  usensor(D8,D9);
+
+
+
+TextLCD lcd( D0,D1, D2, D3, D4, D5,TextLCD::LCD16x2);
+ 
+unsigned int dist;
+
+  
+int main() {
+int angle1;      
+Servo Servo1(D15);
+
+Servo1.Enable(1500,20000);
+
+
+while(1) {
+  
+       
+for (int pos = 0; pos < 2000; pos += 11) {
+        
+        lcd.locate(0,0);
+        Servo1.SetPosition(pos); 
+       angle1 = angle(pos); 
+        lcd.cls();
+        lcd.printf("Angle=%d",angle1, "DEG");
+        printf ("%d", angle1);
+        printf (",");
+        printf ("%d", dist);
+        printf (".");              
+        usensor.start();
+        wait_ms(0); 
+        dist=usensor.get_dist_cm();
+        lcd.locate(0,1);
+        lcd.printf("cm:%ld",dist ); 
+        
+        wait_ms(10);
+        }
+        
+    for (int pos = 2000; pos > 0; pos -= 11) {
+           lcd.locate(0,0);
+        Servo1.SetPosition(pos); 
+       angle1 = angle(pos); 
+        lcd.cls();
+        lcd.printf("Angle=%d",angle1 , "DEG");
+        printf ("%d", angle1);
+        printf (",");
+        printf ("%d", dist);
+        printf (".");               
+        usensor.start();
+        wait_ms(0); 
+        dist=usensor.get_dist_cm();
+        lcd.locate(0,1);
+        lcd.printf("cm:%ld",dist ); 
+        
+        wait_ms(10);
+        
+       }
+        
+    }      
+    
+        
+    
+      }
+      
+      
+int angle (int pos)
+{
+    int angle = (pos / 11 );
+    return angle;
+    }
+    
\ No newline at end of file