upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions

API for the GP2Y0A family of IR Proximity Sensors. More...

Detailed Description

Sensors of this family return an analog voltage corresponding to the distance of an object from the sensor. The voltage is lower when objects are far away; the voltage increases as objects get closer to the sensor.

gp2y0a.jpg
// Note, for the Grove 80cm version of this sensor, due to the way
// it is wired, you need to plug this into the A0 port, where it
// will use the available A1 pin for data.
// Instantiate a GP2Y0A on analog pin A1
upm::GP2Y0A volts(1);
// The higher the voltage (closer to AREF) the closer the object is. NOTE:
// the measured voltage will probably not exceed 3.3 volts.
// Every second, print the averaged voltage value (averaged over 20 samples).
while (shouldRun) {
cout << "AREF: " << GP2Y0A_AREF << ", Voltage value (higher means closer): "
<< volts.value(GP2Y0A_AREF, SAMPLES_PER_QUERY) << endl;
upm_delay(1);
}

Public Member Functions

 GP2Y0A (int pin)
 
 ~GP2Y0A ()
 
float value (float aref, uint8_t samples)
 

Constructor & Destructor Documentation

GP2Y0A ( int  pin)

GP2Y0A sensor constructor

Parameters
pinAnalog pin to use
~GP2Y0A ( )

GP2Y0A destructor

Member Function Documentation

float value ( float  aref,
uint8_t  samples 
)

Gets an average voltage value from the sensor

Parameters
arefReference voltage in use (usually 5.0V or 3.3V)
samplesNumber of samples to average over
Returns
Average voltage reading

The documentation for this class was generated from the following files: