dillerdasker

Dependents:   RoboticHackathon RoboticHackathon2 RoboticHackathonFINAL

Files at this revision

API Documentation at this revision

Comitter:
iLyngklip
Date:
Sat Apr 05 11:26:35 2014 +0000
Parent:
0:506625fdcd0e
Commit message:
plz;

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 506625fdcd0e -r d9083ad270f5 HCSR04.cpp
--- a/HCSR04.cpp	Sat Apr 05 07:55:59 2014 +0000
+++ b/HCSR04.cpp	Sat Apr 05 11:26:35 2014 +0000
@@ -2,7 +2,7 @@
 #include "mbed.h"
 
 
-HCSR04::HCSR04(PinName t, PinName e) : trig(t), echo(e) {}
+HCSR04::HCSR04(PinName t, PinName e, PinName t2, PinName e2) : trig(t), echo(e), trig2(t2), echo2(e2) {}
  
 
 //      Trigger          Echo
@@ -28,7 +28,7 @@
     
     return timer.read_us();
 }
-long HCSR05::Echo_duration() {
+long HCSR04::Echo_duration() {
     timer.reset();
     trig2 = 0;
     wait_us(2);
@@ -59,4 +59,16 @@
         return distacne_cm;
     else
         return distance_inc;
+        }
+        
+long HCSR04::distance(int sys){
+    duration = echo_duration();
+    if(duration > 30000)
+        return -1;
+    distacne_cm = duration /29 / 2 ;
+    distance_inc = duration / 74 / 2;
+    if (sys)
+        return distacne_cm;
+    else
+        return distance_inc;
 }
diff -r 506625fdcd0e -r d9083ad270f5 HCSR04.h
--- a/HCSR04.h	Sat Apr 05 07:55:59 2014 +0000
+++ b/HCSR04.h	Sat Apr 05 11:26:35 2014 +0000
@@ -32,17 +32,17 @@
 
 class HCSR04 {
   public:
-    HCSR04(PinName t, PinName e);
+    HCSR04(PinName t, PinName e, PinName t2, PinName e2);
     long echo_duration();
     long distance(int sys);
     
-    HCSR05();
+    
     long Echo_duration();
     long Distance(int sys);
 
     private:
-        DigitalOut trig;
-        DigitalIn echo;
+        DigitalOut trig, trig2;
+        DigitalIn echo, echo2;
         Timer timer;
         long duration,distacne_cm,distance_inc;
 };