Ultrasound Ranging Sensor module
Revision 8:095071ae3cac, committed 2019-04-27
- Comitter:
- shina
- Date:
- Sat Apr 27 13:38:55 2019 +0000
- Parent:
- 7:71da0dbf4400
- Commit message:
- This is a prototype program about HC-SR04.
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 |
--- 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(); }
--- a/hcsr04.h Sat Mar 30 18:55:03 2013 +0000 +++ b/hcsr04.h Sat Apr 27 13:38:55 2019 +0000 @@ -53,6 +53,9 @@ void isr_fall(void); void fall (void (*fptr)(void)); void rise (void (*fptr)(void)); + + int temperature; + void set_temperature(int temperature);