An echoPing can only be positive as any distance is positive .
That makes it ideal to use the negative values as error codes, but those should be in the primary ping function
something like ..
...
if (time > MAXTIME) return -100;
if (other error) return -200;
// etc
return time;
}
thinking along that line, the conversion function to cm should only accept unsigned ints for echoTime.
unsigned int NewPing::convert_cm(unsigned int echoTime)
{
return (echoTime + US_ROUNDTRIP_CM/2) / US_ROUNDTRIP_CM; // added rounding
}