Pololu 3pi Guía De Usuario página 39

Tabla de contenido

Publicidad

19.
0b00000,
20.
0b00000,
21.
0b00000,
22.
0b00000,
23.
0b00000,
24.
0b00000,
25.
0b11111,
26.
0b11111,
27.
0b11111,
28.
0b11111,
29.
0b11111,
30.
0b11111,
31.
0b11111
32. };
33.
34.
// This function loads custom characters into the LCD.
35.
// characters can be loaded; we use them for 6 levels of a bar graph
36.
// plus a back arrow and a musical note character.
37. void load_custom_characters()
38. {
39.
lcd_load_custom_character(levels+0,0);
40.
lcd_load_custom_character(levels+1,1);
41.
lcd_load_custom_character(levels+2,2);
42.
lcd_load_custom_character(levels+4,3);
43.
lcd_load_custom_character(levels+5,4);
44.
lcd_load_custom_character(levels+6,5);
45.
clear();
// the LCD must be cleared for the characters to take effect
46. }
47.
48.
// 10 levels of bar graph characters
49. const char bar_graph_characters[10] = {' ',0,0,1,2,3,3,4,5,255};
50.
51. void display_levels(unsigned int *sensors)
52. {
53.
clear();
54.
int i;
55.
for(i=0;i<5;i++) {
56.
// Initialize the array of characters that we will use for the
57.
// graph.
58.
// character, and character 255 (a full black box), we get 10
59.
// characters in the array.
60.
61.
// The variable c will have values from 0 to 9, since
62.
// values are in the range of 0 to 1000, and 1000/101 is 9
63.
// with integer math.
64.
char c = bar_graph_characters[sensors[i]/101];
65.
66.
// Display the bar graph characters.
67.
print_character©;
68.
}
69. }
70.
71.
// set the motor speeds
72. void slave_set_motors(int speed1, int speed2)
73. {
74.
char message[4] = {0xC1, speed1, 0xC5, speed2};
75.
if(speed1 < 0)
76.
{
77.
message[0] = 0xC2;
78.
message[1] = -speed1;
79.
}
80.
if(speed2 < 0)
81.
{
82.
message[2] = 0xC6;
83.
message[3] = -speed2;
84.
}
85.
serial_send_blocking(message,4);
86. }
87.
88.
// do calibration
89. void slave_calibrate()
90. {
91.
serial_send("\xB4",1);
92.
int tmp_buffer[5];
93.
94.
// read 10 characters (but we won't use them)
95.
serial_receive_blocking((char *)tmp_buffer, 10, 100);
96. }
97.
98.
// reset calibration
Using the space, an extra copy of the one-bar
// m1 backward
// m2 backward
Up to 8
// no offset, e.g. one bar
// two bars
// etc...
// skip level 3

Publicidad

Tabla de contenido
loading

Productos relacionados para Pololu 3pi

Tabla de contenido