5const auto kMinDistance = 25;
6const auto kMaxDistance = 120;
21 auto result =
static_cast<unsigned int>(9462 / (analogReading - 16.92));
23 return (result >= kMinDistance && result <= kMaxDistance ? result : 0);
unsigned int getDistance() override
Gets the distance measured by the sensor in centimeters.
GP2Y0A02(Runtime &runtime, uint8_t pin)
Constructs a GP2Y0A02 sensor.
An abstract class to represent the various infrared analog sensors.
An interface to serve as a wrapper for the native runtime environment, greatly inspired by the Arduin...
virtual int getAnalogPinState(uint8_t pin)=0
Get pin's analog (ADC) reading, equivalent of analogRead in Arduino.