added float calculation for time to distance conversion

returns higher resolution, especially for measuring in inches the integer resolution was low.
This commit is contained in:
JojoS62
2018-10-02 16:57:33 +02:00
parent e6fdd3380a
commit 15e5edccd8
2 changed files with 11 additions and 0 deletions
+9
View File
@@ -275,3 +275,12 @@ unsigned int NewPingESP8266::convert_in(unsigned int echoTime) {
return NewPingESP8266Convert(echoTime, US_ROUNDTRIP_IN); // Convert uS to inches.
#endif
}
float NewPingESP8266::convert_cm_F(unsigned int echoTime) {
return ((float)echoTime / US_ROUNDTRIP_CM); // Convert uS to centimeters (no rounding).
}
float NewPingESP8266::convert_in_F(unsigned int echoTime) {
return ((float)echoTime / US_ROUNDTRIP_IN); // Convert uS to inches (no rounding).
}
+2
View File
@@ -212,6 +212,8 @@ class NewPingESP8266 {
unsigned long ping_median(uint32_t it = 5, unsigned int max_cm_distance = 0);
static unsigned int convert_cm(unsigned int echoTime);
static unsigned int convert_in(unsigned int echoTime);
static float convert_cm_F(unsigned int echoTime);
static float convert_in_F(unsigned int echoTime);
unsigned int getMaxEchoTime() { return _maxEchoTime; };
errorState getErrorState() { return _errorState; };