wo

Dependents:   Ultrasonic UltrasonicCasper UltrasonicCasper frdm_tsi_slider ... more

Fork of HCSR04 by Awadh Al Shukaili

Files at this revision

API Documentation at this revision

Comitter:
oscargrodri
Date:
Mon May 26 14:10:33 2014 +0000
Parent:
0:0bda99bb39a4
Commit message:
no change

Changed in this revision

HCSR04.cpp Show annotated file Show diff for this revision Revisions of this file
HCSR04.h Show annotated file Show diff for this revision Revisions of this file
diff -r 0bda99bb39a4 -r d388301a0227 HCSR04.cpp
--- a/HCSR04.cpp	Tue Oct 18 14:32:12 2011 +0000
+++ b/HCSR04.cpp	Mon May 26 14:10:33 2014 +0000
@@ -7,13 +7,14 @@
 //      Trigger          Echo
 //      _______           _____________,,,,,,,,,
 // ____|  10us |_________| 150us-25ms, or 38ms if no obstacle
-// 
+//
 
 //return echo duration in us (refer to digram above)
-long HCSR04::echo_duration() {
+int HCSR04::echo_duration()
+{
     timer.reset();
     trig = 0;
-    wait_us(2);
+    wait_us(10);
     trig = 1;
     wait_us(10);
     trig = 0;
@@ -24,15 +25,14 @@
     return timer.read_us();
 }
 
-//return distance to nearest obstacle or returns -1 
+//return distance to nearest obstacle or returns -1
 //if no obstacle within range
 //set sys to cm or inch accordingly
-long HCSR04::distance(int sys){
+int HCSR04::distance(int sys)
+{
     duration = echo_duration();
-    if(duration > 30000)
-        return -1;
-    distacne_cm = duration /29 / 2 ;
-    distance_inc = duration / 74 / 2;
+    distacne_cm = duration  /29/2;
+    distance_inc = duration /74/2;
     if (sys)
         return distacne_cm;
     else
diff -r 0bda99bb39a4 -r d388301a0227 HCSR04.h
--- a/HCSR04.h	Tue Oct 18 14:32:12 2011 +0000
+++ b/HCSR04.h	Mon May 26 14:10:33 2014 +0000
@@ -26,14 +26,14 @@
 class HCSR04 {
   public:
     HCSR04(PinName t, PinName e);
-    long echo_duration();
-    long distance(int sys);
+    int echo_duration();
+    int distance(int sys);
 
     private:
         DigitalOut trig;
         DigitalIn echo;
         Timer timer;
-        long duration,distacne_cm,distance_inc;
+        int duration,distacne_cm,distance_inc;
 };
 
 #endif
\ No newline at end of file