User Manual

provided by the library. For example, if pins is {IO_D3, IO_D6, IO_C1}, sensor 0 is on PD3, sensor
1 is on PD6, and sensor 2 is on PC1.
For ATmegaxx8-based controllers, the pin numbers are Arduino-compatible so you can define the
pins array using Arduino pin numbers. For example, if pins is {3, 6, 15}, sensor 0 is on digital pin 3
or PD3, sensor 1 is on digital pin 6 or PD6, and sensor 2 is on digital pin 15 or PC1 (Arduino analog
input 1). Digital pins 0 7 correpsond to port D pins PD0 PD7, respectively. Digital pins 8 13
correspond to port B pins PB0 PB5. Digital pins 14 19 correspond to port C pins PC0 PC5,
which are referred to in the Arduino environment as analog inputs 0 – 5.
numSensors specifies the length of the ‘pins’ array (the number of QTR-RC sensors you are using).
numSensors must be no greater than 16.
timeout specifies the length of time in Timer2 counts beyond which you consider the sensor reading
completely black. That is to say, if the pulse length for a pin exceeds timeout, pulse timing will stop
and the reading for that pin will be considered full black. It is recommended that you set timeout to
be between 1000 and 3000 us, depending on factors like the height of your sensors and ambient
lighting. This allows you to shorten the duration of a sensor-reading cycle while maintaining useful
measurements of reflectance. On a 16 MHz microcontroller, you can convert Timer2 counts to
microseconds by dividing by 2 (2000 us = 4000 Timer2 counts = timeout of 4000). On a 20 MHz
microcontroller, you can convert Timer2 counts to microseconds by dividing by 2.5 or multiplying by
0.4 (2000 us = 5000 Timer2 counts = timeout of 5000).
emitterPin is the Arduino digital pin that controls whether the IR LEDs are on or off. This pin is
optional and only exists on the 8A and 8RC QTR sensor arrays. If a valid pin is specified, the
emitters will only be turned on during a reading. If an invalid pin is specified (e.g. 255), the IR
emitters will always be on.
PololuQTRSensorsAnalog::PololuQTRSensorsAnalog()
This constructor performs no initialization. If this constructor is used, the user must call init() before
using the methods in this class.
PololuQTRSensorsAnalog::PololuQTRSensorsAnalog(unsigned char* analogPins, unsigned
char numSensors, unsigned char numSamplesPerSensor = 4, unsigned char emitterPin = 255)
This constructor just calls init(), below.
void PololuQTRSensorsAnalog::init(unsigned char* analogPins, unsigned char numSensors,
unsigned char numSamplesPerSensor = 4, unsigned char emitterPin = 255)
void qtr_analog_init(unsigned char* analogPins, unsigned char numSensors, unsigned char
numSamplesPerSensor, unsigned char emitterPin)
Initializes a QTR-A (analog) sensor array.
The array pins contains the analog pin assignment for each sensor. For example, if pins is {0, 1, 7},
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation
16. QTR Reflectance Sensors Page 68 of 77