Pololu 3pi Robot User Manual
Page 59
// print to the slave LCD
void slave_print(char *string)
{
serial_send_blocking("\xB8", 1);
char length = strlen(string);
serial_send_blocking(&length, 1); // send the string length
serial_send_blocking(string, length);
}
// go to coordinates x,y on the slave LCD
void slave_lcd_goto_xy(char x, char y)
{
serial_send_blocking("\xB9",1);
serial_send_blocking(&x,1);
serial_send_blocking(&y,1);
}
int main()
{
char buffer[20];
// load the bar graph
load_custom_characters();
// configure serial clock for 115.2 kbaud
serial_set_baud_rate(115200);
// wait for the device to show up
while(1)
{
clear();
print("Master");
delay_ms(100);
serial_send("\x81",1);
if(serial_receive_blocking(buffer, 6, 50))
continue;
clear();
print("Connect");
lcd_goto_xy(0,1);
buffer[6] = 0;
print(buffer);
// clear the slave's LCD and display "Connect" and "OK" on two lines
// Put OK in the center to test x-y positioning
slave_clear();
slave_print("Connect");
slave_lcd_goto_xy(3,1);
slave_print("OK");
// play a tune
char tune[] = "\xB3 l16o6gab>c";
tune[1] = sizeof(tune)-3;
serial_send_blocking(tune,sizeof(tune)-1);
// wait
wait_for_button(ALL_BUTTONS);
// reset calibration
slave_reset_calibration();
time_reset();
slave_auto_calibrate();
unsigned char speed1 = 0, speed2 = 0;
// read sensors in a loop
while(1)
{
serial_send("\x87",1); // returns calibrated sensor values
// read 10 characters
if(serial_receive_blocking(buffer, 10, 100))
break;
Pololu 3pi Robot User's Guide
© 2001–2014 Pololu Corporation
10. Expansion Information
Page 59 of 63