upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions
GP2Y0A Class Reference

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.

// 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 = new upm::GP2Y0A(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;

Public Member Functions

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

Constructor & Destructor Documentation

GP2Y0A ( int  pin)

GP2Y0A sensor constructor

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

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

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