User Manual

Reference
C++ and methods are shown in red.
C functions are shown in green.
void PololuQTRSensors::read(unsigned int *sensorValues, unsigned char readMode =
QTR_EMITTERS_ON)
void qtr_read(unsigned int *sensorValues, unsigned char readMode)
Reads the raw sensor values into an array. There MUST be space for as many values as there were sensors
specified in the constructor. The values returned are a measure of the reflectance in units that depend on the
type of sensor being used, with higher values corresponding to lower reflectance (a black surface or a void).
QTR-xA sensors will return a raw value between 0 and 1023. QTR-xRC sensors will return a raw value
between 0 and the timeout argument provided in the constructor (which defaults to 4000). The units will be in
Timer2 counts, where Timer2 is running at the CPU clock divided by 8 (i.e. 2 MHz on a 16 MHz processor,
or 2.5 MHz on a 20 MHz processor).
The functions that read values from the sensors all take an argument readMode, which specifies the kind of
read that will be performed. Several options are defined: QTR_EMITTERS_OFF specifies that the reading
should be made without turning on the infrared (IR) emitters, in which case the reading represents ambient
light levels near the sensor; QTR_EMITTERS_ON specifies that the emitters should be turned on for
the reading, which results in a measure of reflectance; and QTR_EMITTERS_ON_AND_OFF specifies
that a reading should be made in both the on and off states. The values returned when the
QTR_EMITTERS_ON_AND_OFF option is used are given by on + max – off, where on is the reading with
the emitters on, off is the reading with the emitters off, and max is the maximum sensor reading. This option
can reduce the amount of interference from uneven ambient lighting. Note that emitter control will only work
if you specify a valid emitter pin in the constructor.
Example usage:
unsigned int sensor_values[8];
sensors.read(sensor_values);
void PololuQTRSensors::emittersOn()
void qtr_emitters_on()
Turn the IR LEDs on. This is mainly for use by the read method, and calling these functions before or after
the reading the sensors will have no effect on the readings, but you may wish to use these for testing purposes.
This method will only do something if a valid emitter pin was specified in the constructor.
void PololuQTRSensors::emittersOff()
void qtr_emitters_off()
Turn the IR LEDs off. This is mainly for use by the read method, and calling these functions before or after
the reading the sensors will have no effect on the readings, but you may wish to use these for testing purposes.
void PololuQTRSensors::calibrate(unsigned char readMode = QTR_EMITTERS_ON)
void qtr_calibrate(unsigned char readMode)
Reads the sensors for calibration. The sensor values are not returned; instead, the maximum and minimum
values found over time are stored internally and used for the readCalibrated() method. You can access the
calibration (i.e raw max and min sensor readings) through the public member pointers calibratedMinimumOn,
calibratedMaximumOn, calibratedMinimumOff, and calibratedMaximumOff. Note that these pointers will
point to arrays of length numSensors, as specified in the constructor, and they will only be allocated after
calibrate() has been called. If you only calibrate with the emitters on, the calibration arrays that hold the off
values will not be allocated.
Pololu AVR Library Command Reference © 2001–2015 Pololu Corporation
16. QTR Reflectance Sensors Page 54 of 65