User Guide

21. const char welcome[] PROGMEM = “>g32>>c32”;
22. const char go[] PROGMEM = “L16 cdegreg4”;
23. // Data for generating the characters used in load_custom
] starting a
_characters
t various
n loads custom characters into the LCD. Up to 8
can be loaded; we use them for 7 levels of a bar graph.
tom_characters()
els+2,2); // etc...
e characters to take effect
he
space, an extra copy of the one-bar
acter 255 (a full black box), we get 10
essage, calibrates, and
.
an array to hold sensor values
ed at the beginning of 3pi code, to set up the
hich
_space(demo_name_line2);
ress
24. // and display_readings. By reading levels[
25. // offsets, we can generate all of the 7 extra characters needed for a
26. // bargraph. This is also stored in program space.
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
oad_cus45. void l
46. {
47. lcd_load_custom_character(levels+0,0); // no offset, e.g. one bar
ls+1,1); // two bars 48. lcd_load_custom_character(leve
d_load_custom_character(lev49. lc
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++) {
Initialize the array of characters that we will use for t61. //
62. // graph. Using the
63. // character, and char
64. // characters in the array.
255};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. }
plays a welcome m74. // Initializes the 3pi, dis
the initial music75. // plays
76. void initialize()
77. {
d as a simple timer 78. unsigned int counter; // use
rs[5]; //79. unsigned int senso
is must be call80. // Th
81. // sensors. We use a value of 2000 for the timeout, w
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(welc
ome_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();
ne1); 92. print_from_program_space(demo_name_li
93. lcd_goto_xy(0,1);
rogram94. print_from_p
95. delay_ms(1000);
ge and wait for button p96. // Display battery volta
97. while(!button_is_pressed(BUTTON_B))
98. {
99. int bat = read_battery_millivolts();
100. clear();