21.
const char welcome[] PROGMEM = ">g32>>c32";
22.
const char go[] PROGMEM = "L16 cdegreg4";
23.
// Data for generating the characters used in load_custom
24.
// and display_readings.
25.
// offsets, we can generate all of the 7 extra characters needed for a
26.
// bargraph.
27.
const char levels[] PROGMEM = {
28.
0b00000,
29.
0b00000,
30.
0b00000,
31.
0b00000,
32.
0b00000,
33.
0b00000,
34.
0b00000,
35.
0b11111,
36.
0b11111,
37.
0b11111,
38.
0b11111,
39.
0b11111,
40.
0b11111,
41.
0b11111
42.
};
43.
// This functio
44.
// characters
45.
void l
oad_cus
46.
{
47.
lcd_load_custom_character(levels+0,0); // no offset, e.g. one bar
48.
lcd_load_custom_character(leve
49.
lc
d_load_custom_character(lev
50.
lcd_load_custom_character(levels+3,3);
51.
lcd_load_custom_character(levels+4,4);
52.
lcd_load_custom_character(levels+5,5);
53.
lcd_load_custom_character(levels+6,6);
54.
clear(); // the LCD must be cleared for th
55.
}
56.
// This function displays the sensor readings using a bar graph.
57.
void display_readings(const unsigned int *calibrated_values)
58.
{
59.
unsigned char i;
60.
for(i=0;i<5;i++) {
61.
//
Initialize the array of characters that we will use for t
62.
// graph.
63.
// character, and char
64.
// characters in the array.
65.
const char display_characters[10] = {' ',0,0,1,2,3,4,5,6,
66.
// The variable c will have values from 0 to 9, since
67.
// calibrated values are in the range of 0 to 1000, and
68.
// 1000/101 is 9 with integer math.
69.
char c = display_characters[calibrated_values[i]/101];
70.
// Display the bar graph character.
71.
print_character©;
72.
}
73.
}
74.
// Initializes the 3pi, dis
75.
// plays
the initial music
76.
void initialize()
77.
{
78.
unsigned int counter; // use
79.
unsigned int senso
80.
// Th
is must be call
81.
// sensors.
82.
// corresponds to 2000*0.4 us = 0.8 ms on our 20 MHz processor.
83.
pololu_3pi_init(2000);
84.
load_custom_characters(); // load the custom characters
85.
// Play welcome music and display a message
86.
print_from_program_space(welcome_line1);
87.
lcd_goto_xy(0,1);
88.
print_from_program_space(welcome_line2);
89.
play_from_program_space(welcome);
90.
delay_ms(1000);
91.
clear();
92.
print_from_program_space(demo_name_li
93.
lcd_goto_xy(0,1);
94.
print_from_p
95.
delay_ms(1000);
96.
// Display battery volta
97.
while(!button_is_pressed(BUTTON_B))
98.
{
99.
int bat = read_battery_millivolts();
100.
clear();
By reading levels[
This is also stored in program space.
n loads custom characters into the LCD.
can be loaded; we use them for 7 levels of a bar graph.
tom_characters()
els+2,2); // etc...
Using the
space, an extra copy of the one-bar
acter 255 (a full black box), we get 10
plays a welcome m
.
d as a simple timer
rs[5]; //
an array to hold sensor values
ed at the beginning of 3pi code, to set up the
We use a value of 2000 for the timeout, w
rogram
_space(demo_name_line2);
ge and wait for button p
] starting a
ls+1,1); // two bars
e characters to take effect
essage, calibrates, and
ne1);
ress
_characters
t various
Up to 8
he
255};
hich