create
Dependents: Nucleo_UltrasonicHelloWorld
Fork of HCSR04 by
Revision 1:a6912eacfb20, committed 2015-08-10
- Comitter:
- ryuhs74
- Date:
- Mon Aug 10 01:02:07 2015 +0000
- Parent:
- 0:86b2086be101
- Commit message:
- z
Changed in this revision
hcsr04.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 86b2086be101 -r a6912eacfb20 hcsr04.cpp --- a/hcsr04.cpp Mon Apr 14 08:23:09 2014 +0000 +++ b/hcsr04.cpp Mon Aug 10 01:02:07 2015 +0000 @@ -4,26 +4,26 @@ *HCSR04.cpp */ HCSR04::HCSR04(PinName t, PinName e) : trig(t), echo(e) {} - long HCSR04::echo_duration() { - + +long HCSR04::echo_duration() { timer.reset(); //reset timer trig=0; // trigger low wait_us(2); // wait trig=1; // trigger high wait_us(10); trig=0; // trigger low - while(!echo); // start pulseIN - timer.start(); - while(echo); - timer.stop(); - return timer.read_us(); - + + while(!echo); // start pulseIN + timer.start(); + + while(echo); + timer.stop(); + return timer.read_us(); } - + //return distance in cm long HCSR04::distance(){ duration = echo_duration(); - distance_cm = (duration/2)/29.1 ; - return distance_cm; - + distance_cm = (duration/2)/29.1 ; + return distance_cm; } \ No newline at end of file