dillerdasker
Dependents: RoboticHackathon RoboticHackathon2 RoboticHackathonFINAL
Diff: HCSR04.cpp
- Revision:
- 1:d9083ad270f5
- Parent:
- 0:506625fdcd0e
--- 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; }