Source code – Pololu 3pi Robot User Manual
Page 57

• GND-GND
• PD0-PD1
• PD1-PD0
Turn on both master and slave. The master will display a “Connect” message followed by the signature of the slave
source code (e.g. “3pi1.0”). The master will then instruct the slave to display “Connect” and play a short tune.
Pressing the B botton on the master causes the slave to go through an auto-calibration routine, after which you can
drive the slave around using the A and C buttons on the master, while viewing sensor data on the master’s LCD.
Holding down the B button causes the slave to do PID line following.
Source code
#include
#include
/*
* 3pi-serial-master - An example serial master program for the Pololu
* 3pi Robot. This can run on any board supported by the library;
* it is intended as an example of how to use the master/slave
* routines.
*
* http://www.pololu.com/docs/0J21
* http://www.pololu.com/docs/0J20
* http://www.poolu.com/
*/
// Data for generating the characters used in load_custom_characters
// and display_readings. By reading levels[] starting at various
// offsets, we can generate all of the 7 extra characters needed for a
// bargraph. This is also stored in program space.
const char levels[] PROGMEM = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};
// This function loads custom characters into the LCD. Up to 8
// characters can be loaded; we use them for 6 levels of a bar graph
// plus a back arrow and a musical note character.
void load_custom_characters()
{
lcd_load_custom_character(levels+0,0); // no offset, e.g. one bar
lcd_load_custom_character(levels+1,1); // two bars
lcd_load_custom_character(levels+2,2); // etc...
lcd_load_custom_character(levels+4,3); // skip level 3
lcd_load_custom_character(levels+5,4);
lcd_load_custom_character(levels+6,5);
clear(); // the LCD must be cleared for the characters to take effect
}
// 10 levels of bar graph characters
const char bar_graph_characters[10] = {' ',0,0,1,2,3,3,4,5,255};
void display_levels(unsigned int *sensors)
{
clear();
int i;
for(i=0;i<5;i++) {
// Initialize the array of characters that we will use for the
// graph. Using the space, an extra copy of the one-bar
Pololu 3pi Robot User's Guide
© 2001–2014 Pololu Corporation
10. Expansion Information
Page 57 of 63