Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of HCSR04 by
Diff: HCSR04.cpp
- Revision:
- 4:aae70f15357f
- Parent:
- 3:9a7899cf5e3a
- Child:
- 6:cf3e4e307d15
--- a/HCSR04.cpp Sun Dec 06 15:13:54 2015 +0000 +++ b/HCSR04.cpp Mon Dec 07 09:37:21 2015 +0000 @@ -13,7 +13,7 @@ echo.fall(this, &HCSR04::stopTimer); distance = -1; // initial distance - minDistance = 4; + minDistance = 2; maxDistance = 400; } @@ -42,4 +42,26 @@ float HCSR04::getDistance_cm() { startMeasurement(); return distance; +} + +float HCSR04::getDistance_mm() { + startMeasurement(); + return distance * 10; +} + +void HCSR04::setRanges(float minRange, float maxRange) { + if (minRange < maxRange) { + if (minRange >= 2) + minDistance = minRange; + if (maxRange <= 400) + maxDistance = maxRange; + } +} + +float HCSR04::getMinRange() { + return minDistance; +} + +float HCSR04::getMaxRange() { + return maxDistance; } \ No newline at end of file