User Guide

98. return;
99. set_m2_speed(byte == 127 ? -255 : -byte*2);
100. }
101. // A buffer to store the music that will play in the background.
102. char music_buffer[100];
103. // Plays a musical sequence.
104. void do_play()
105. {
106. unsigned char tune_length = read_next_byte();
107. if(check_data_byte(tune_length))
108. return;
109. unsigned char i;
110. for(i=0;i<tune_length;i++)
111. {
112. if(i > sizeof(music_buffer)) // avoid overflow
113. return;
114. music_buffer[i] = read_next_byte();
115. if(check_data_byte(music_buffer[i]))
116. return;
117. }
118. // add the end of string character 0
119. music_buffer[i] = 0;
120. play(music_buffer);
121. }
122. // Clears the LCD
123. void do_clear()
124. {
125. clear();
126. }
127. // Displays data to the screen
128. void do_print()
129. {
130. unsigned char string_length = read_next_byte();
131.
if(check_data_byte(string_length))
132. return;
133. unsigned char i;
134. for(i=0;i<string_length;i++)
135. {
136. unsigned char character;
137. character = read_next_byte();
138. if(check_data_byte(character))
139. return;
140. // Before printing to the LCD we need to go to AUTOMATIC mode.
141. // Otherwise, we might miss characters during the lengthy LCD routines.
142. serial_set_mode(SERIAL_AUTOMATIC);
143. print_character(character);
144. serial_set_mode(SERIAL_CHECK);
145. }
146. }
147. // Goes to the x,y coordinates on the lcd specified by the two data bytes
148. void do_lcd_goto_xy()
149. {
150. unsigned char x = read_next_byte();
151. if(check_data_byte(x))
152. return;
153. unsigned char y = read_next_byte();
154. if(check_data_byte(y))
155. return;
156. lcd_goto_xy(x,y);
157. }
158. // Runs through an automatic calibration sequence
159. void auto_calibrate()
160. {
161. time_reset();
162. set_motors(60, -60);
163. while(get_ms() < 250)
164. calibrate_line_sensors(IR_EMITTERS_ON);
165.
set_motors(-60, 60);
166. while(get_ms() < 750)
167. calibrate_line_sensors(IR_EMITTERS_ON);
168. set_motors(60, -60);
169. while(get_ms() < 1000)
170. calibrate_line_sensors(IR_EMITTERS_ON);
171. set_motors(0, 0);
172. serial_send_blocking(ā€œcā€,1);
173. }
174. // Turns on PID according to the supplied PID constants
175. void set_pid()
176. {
177. unsigned char constants[5];