63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
lcd_load_custom_character(2,2);
// etc...
lcd_load_custom_character(3,3);
lcd_load_custom_character(4,4);
lcd_load_custom_character(5,5);
lcd_load_custom_character(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();
Pololu 3pi Robot User’s Guide
© 2001–2019 Pololu Corporation
7. Example Project #1: Line Following
Page 32 of 85
Содержание 0J5840
Страница 24: ...Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 5 How Your 3pi Works Page 24 of 85...
Страница 67: ...Source code Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 10 Expansion Information Page 67 of 85...
Страница 77: ...Source code Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 10 Expansion Information Page 77 of 85...