A library for the HCSR04 sensor. work with interrupt

Dependents:   AdrianLysShow AdrianLysShow

A small library for the HCSR04 sensor. works with interrupt on the egde of the echo

link to datasheet: http://www.micropik.com/PDF/HCSR04.pdf

Revision:
1:e3a37f4015da
Parent:
0:9f4365d41bf1
--- a/HCSR04.cpp	Tue Apr 28 14:46:20 2015 +0000
+++ b/HCSR04.cpp	Wed Apr 29 06:12:22 2015 +0000
@@ -1,6 +1,6 @@
 #include "HCSR04.h"
 #include "mbed.h"
-#define DistanceOffset 180
+#define DistanceOffset 0
 HCSR04::HCSR04(PinName t, PinName e,callback_type _callback) : trig(t), echo(e) 
 {
  echo.rise(this, &HCSR04::StartTimer); 
@@ -16,11 +16,12 @@
 
 void HCSR04::DistResult() {
 //Getting the distance
- dist_cm =timer.read_us()-DistanceOffset;
- callback(dist_cm*0.034);   //time the speed of sound
+ dist_cm =((timer.read_us()-DistanceOffset)*0.034)/2;
+ callback(dist_cm);   //time the speed of sound
 }
 
 void HCSR04::Trigoff() {
+//setting the trigger low    
     trig = 0;
 }