AVR Library Command Reference
Table Of Contents
- Pololu AVR Library Command Reference
- 1. Introduction
- 2. Timing and Delays
- Reference
- 3. Orangutan Analog-to-Digital Conversion
- Reference
- 4. Orangutan Buzzer: Beeps and Music
- Reference
- 5. Orangutan LCD
- Reference
- 6. Orangutan LEDs
- Reference
- 7. Orangutan Motor Control
- Reference
- 8. Orangutan Pushbuttons
- Reference
- 9. Orangutan Serial Port Communication
- Reference
- 10. Orangutan System Resources
- 11. QTR Reflectance Sensors
- Reference
- 12. 3pi Robot Functions
- 13. Wheel Encoders
- Reference
Reference
C++ and Arduino methods are shown in red.
C functions are shown in green.
static void PololuWheelEncoders::init(unsigned char a1, unsigned char a2, unsigned char b1, unsigned char
b2)
void encoders_init(unsigned char a1, unsigned char a2, unsigned char b1, unsigned char b2)
Initializes the wheel encoders. The four arguments are the four pins that the wheel encoders are connected to,
according to the Arduino numbering: Arduino digital pins 0 – 7 correpsond to port D pins PD0 – PD7,
respectively. Arduino digital pins 8 – 13 correspond to port B pins PB0 – PB5. Arduino analog inputs 0 – 5 are
referred to as digital pins 14 – 19 (these are the enumerations you should use for this library) and correspond to
port C pins PC0 – PC5. The arguments are named a1, a2, etc. with the intention that when motor A is spinning
forward, pin a1 will change before pin a2. However, it is difficult to get them all correct on the first try, and you
might have to experiment.
static int getCountsA()
static int getCountsB()
int encoders_get_counts_a()
int encoders_get_counts_b()
Returns the number of counts measured on A or B. For the Pololu wheel encoders, the resolution is about 3mm/
count, so this allows a maximum distance of 32767 × 3mm or about 100m. For longer distances, you will need to
occasionally reset the counts using the functions below.
static int getCountsAndResetA()
static int getCountsAndResetB()
int encoders_get_counts_and_reset_a()
int encoders_get_counts_and_reset_b()
Returns the number of counts measured on A or B, and resets the stored value to zero.
static unsigned char checkErrorA()
static unsigned char checkErrorB()
unsigned char encoders_check_error_a()
unsigned char encoders_check_error_b()
These functions check whether there has been an error on A or B; that is, if both a1/a2 or b1/b2 changed
simultaneously. They return 1 if there was an error, then reset the error flag.
Pololu AVR Library Command Reference © 2001–2009 Pololu Corporation
13. Wheel Encoders Page 35 of 35










