Ultrasound Ranging Sensor module

Dependents:   HC-SR04

Revision:
8:095071ae3cac
Parent:
6:4be4fcd0c171
diff -r 71da0dbf4400 -r 095071ae3cac hcsr04.cpp
--- a/hcsr04.cpp	Sat Mar 30 18:55:03 2013 +0000
+++ b/hcsr04.cpp	Sat Apr 27 13:38:55 2019 +0000
@@ -29,6 +29,7 @@
     echo.rise(this,&HCSR04::isr_rise);
     echo.fall(this,&HCSR04::isr_fall);
     trigger=0;
+    this->temperature=25;
 }
 
 HCSR04::~HCSR04()
@@ -45,12 +46,16 @@
     wait_us(10);
     trigger=0;
 }
+void HCSR04::set_temperature(int temperature)
+{
+    this->temperature=temperature;
+}
 
 void HCSR04::isr_fall(void)
 {
     pulsetime.stop();
     pulsedur = pulsetime.read_us();
-    distance= (pulsedur*343)/20000;
+    distance=(pulsedur*(331.5+temperature*0.6)/20000);
     pulsetime.reset();
 }