Pololu 3pi Robot User Manual

Page 25

Advertising
background image

lcd_load_custom_character(levels+4,4);

lcd_load_custom_character(levels+5,5);

lcd_load_custom_character(levels+6,6);

clear(); // the LCD must be cleared for the characters to take effect

}

// This function displays the sensor readings using a bar graph.

void display_readings(const unsigned int *calibrated_values)

{

unsigned char 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

// character, and character 255 (a full black box), we get 10

// characters in the array.

const char display_characters[10] = {' ',0,0,1,2,3,4,5,6,255};

// The variable c will have values from 0 to 9, since

// calibrated values are in the range of 0 to 1000, and

// 1000/101 is 9 with integer math.

char c = display_characters[calibrated_values[i]/101];

// Display the bar graph character.

print_character(c);

}

}

// Initializes the 3pi, displays a welcome message, calibrates, and

// plays the initial music.

void initialize()

{

unsigned int counter; // used as a simple timer

unsigned int sensors[5]; // an array to hold sensor values

// This must be called at the beginning of 3pi code, to set up the

// sensors. We use a value of 2000 for the timeout, which

// corresponds to 2000*0.4 us = 0.8 ms on our 20 MHz processor.

pololu_3pi_init(2000);

load_custom_characters(); // load the custom characters

// Play welcome music and display a message

print_from_program_space(welcome_line1);

lcd_goto_xy(0,1);

print_from_program_space(welcome_line2);

play_from_program_space(welcome);

delay_ms(1000);

clear();

print_from_program_space(demo_name_line1);

lcd_goto_xy(0,1);

print_from_program_space(demo_name_line2);

delay_ms(1000);

// Display battery voltage and wait for button press

while(!button_is_pressed(BUTTON_B))

{

int bat = read_battery_millivolts();

clear();

print_long(bat);

print("mV");

lcd_goto_xy(0,1);

print("Press B");

delay_ms(100);

}

// Always wait for the button to be released so that 3pi doesn't

// start moving until your hand is away from it.

wait_for_button_release(BUTTON_B);

delay_ms(1000);

// Auto-calibration: turn right and left while calibrating the

// sensors.

for(counter=0;counter<80;counter++)

{

Pololu 3pi Robot User's Guide

© 2001–2014 Pololu Corporation

7. Example Project #1: Line Following

Page 25 of 63

Advertising