Ultrasonic searcher with Servo controlled by PC

Dependencies:   HCSR04 Servo TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
Birkan
Date:
Wed Nov 13 22:25:05 2013 +0000
Child:
1:3707e73808d1
Commit message:
ss

Changed in this revision

HCSR04.lib Show annotated file Show diff for this revision Revisions of this file
Servo.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.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
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/HCSR04.lib	Wed Nov 13 22:25:05 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/prabhuvd/code/HCSR04/#71da0dbf4400
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Wed Nov 13 22:25:05 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Nov 13 22:25:05 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#e4cb7ddee0d3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 13 22:25:05 2013 +0000
@@ -0,0 +1,106 @@
+#include "mbed.h"
+#include "Servo.h"
+#include "hcsr04.h"
+#include "TextLCD.h"
+
+Serial pc(USBTX, USBRX);         // pc & mbed seri iletişimi
+TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7  LCD pin bağlantısı
+Servo myservo(p21);   // servo pin girişi
+DigitalOut hedef_var(LED1);
+DigitalOut working(LED2);
+DigitalOut open(LED3);
+DigitalOut close(LED4);
+HCSR04  usensor(p25,p9);  // ultrasonic sensor trig, echo pinleri
+
+int dist;   // distance için 'd' 
+char c;    // pc den alınan karakter için 'c'
+float p;
+
+int main() 
+{
+
+working=1;  // çalıştığını gösteriyor
+
+while(1)
+  {     
+    
+
+    
+      for(p=0.0; p<=1.0; p += 0.05)  // servo için adım
+         { 
+           usensor.start();                                // usensor sinyal gönderiyor
+           wait_ms(500);      
+           dist=usensor.get_dist_cm();                     // sinyal dönüşü mesafe hesabı
+           lcd.cls();                   
+           lcd.locate(0,0);             
+           lcd.printf("Obs Range cm:%ld",dist);            // LCD ye mesafe yazdırılıyor 
+           printf("%d\n ",dist); //
+           printf("%f\n ",p);    // 
+                                          
+         
+              if(dist<50)                                  //30 cm den az hedef varsa doğrulamak için
+               { 
+                 lcd.cls();
+                 lcd.locate(0,0);
+                 lcd.printf("Obs Range cm:%ld",dist);
+                 lcd.locate(0,1);
+                 lcd.printf("location :%f",p);
+                 hedef_var=1;                
+                 }
+                 
+                 else if(dist>50)
+                 {
+                  hedef_var=0;
+                     
+                 }
+                
+   
+           myservo = p;
+           wait(0.2); 
+           
+
+        }
+          
+        // SERVO GERİ DÖNÜYOR //
+
+       for(p=1.0; p>0.0; p -=0.05)
+         {
+           usensor.start();
+           wait_ms(500);     
+           dist=usensor.get_dist_cm(); 
+           lcd.cls();                   
+           lcd.locate(0,0);             
+           lcd.printf("Obs Range cm:%ld",dist); 
+           printf(" %d\n ",dist); //
+           printf("%f\n ",p);    // 
+                                          
+              if(dist<=50)
+               { 
+
+     
+                 lcd.cls();
+                 lcd.locate(0,0);
+                 lcd.printf("Obs Range cm:%ld",dist);
+                 lcd.locate(0,1);
+                 lcd.printf("location :%f",p);
+                 hedef_var=1;                      
+                 }
+                 else if(dist>50)
+                 {
+                  hedef_var=0;
+                 }
+                
+  
+           myservo = p;
+           wait(0.2); 
+
+
+           }
+
+          }
+       
+ 
+    
+    
+     }
+  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 13 22:25:05 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file