NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7

AWOL:
You've got two virtually-identical constructors; you could eliminate code by defaulting "max_cm_distance" to "MAX_SENSOR_DISTANCE", couldn't you?

I created two constructors to be compatible with existing ping/ultrasonic libraries that only pass 2 variables. I would expect users to use the one that sets the maximum distance. I also wouldn't expect someone to use both in the same sketch, so there's no wasted compiled code space as only one would be compiled. I would love to consolidate the two, as they're basically identical. But, I lack the knowledge of C++ to accommodate a constructor that has a different number of variables to pass while keeping the same constructor name. I come from very long PHP programming background but haven't touched C in at least 20 years. In PHP I would do something like this:

function NewPing(trigger_pin, echo_pin, max_cm_distance=MAX_SENSOR_DISTANCE) {...}

AWOL:

int NewPing::convert_cm(int echoTime) {
if (!echoTime) return false;
else return echoTime / US_ROUNDTRIP_CM;

}



If "echoTime" is zero, then "echoTime / US_ROUNDTRIP_CM" is also zero; no need to test up front - slightly longer execution time, shorter code.

Inexperience on my part and confusion with other languages. I think of false as not the same as zero. false !== 0. If false === 0 (strict) in Arduino, that changes many things.

Tim