/// <summary>
/// _mapGP2Y0A21YK_CM: calculates the distance in centimeters using a LUT (LUT filled with data calculated by the inverse tranferfunction)
///    -> Two different LUTs depending on ADC reference voltage
/// </summary>
int DistanceGP2Y0A21YK::_mapGP2Y0A21YK_CM(int value)
{
	if (_refVoltage == 3)
	{
		int sum = 0;
		for (int i=0;i<_average;i++)
		{
			sum=sum + pgm_read_byte_near (transferFunctionLUT3V + (getDistanceRaw()/4));
		}
		return(sum/_average);
	}
	else
	{
		int sum = 0;
		for (int i=0;i<_average;i++)
		{
			sum=sum + pgm_read_byte_near (transferFunctionLUT5V + (getDistanceRaw()/4));
		}
		return(sum/_average);
	}
}
/// <summary>
/// getDistanceCentimeter(): Returns the distance in centimeters
/// </summary>
int DistanceGP2Y0A21YK::getDistanceCentimeter()
{
	return _mapGP2Y0A21YK_CM(getDistanceRaw());
}
/// <summary>
/// getDistanceVolt(): Returns the distance as a Voltage: ADC Input: 0V -> 5V (or 0V -> 3.3V)
/// </summary>
int DistanceGP2Y0A21YK::getDistanceVolt()
{
	return _mapGP2Y0A21YK_V(getDistanceRaw());
}
double GP2Y0A21YK0F::getDistanceVolt()
{
	return (getDistanceRaw()*0.0049);
}
/// getDistanceVolt(): Returns the distance as a Voltage: ADC Input: 0V -> 5V (or 0V -> 3.3V)
int AnalogDistanceSensor::getDistanceVolt()
{
  return _mapGP2Y0A21YK_V(getDistanceRaw());
}
Example #6
0
/**
 *  Calculate the distance
 * 
 *  The value is read from the analogue pin and converted to a distance.
 * 
 *  \return distance in cm
 */
uint16_t GP2Y0A02F::getDistanceCm()
{
  return getDistanceCm( getDistanceRaw() );
}