User Guide

99. void slave_reset_calibration()
100. {
serial_send_blocking(“\xB5”,1);
101. }
102.
103. // calibrate (waits for a 1-byte response to indicate completion)
104. void slave_auto_calibrate()
105. {
106. int tmp_buffer[1];
107. serial_send_blocking(“\xBA”,1);
108. serial_receive_blocking((char *)tmp_buffer, 1, 10000);
109. }
110.
111. // sets up the pid constants on the 3pi for line following
112. void slave_set_pid(char max_speed, char p_num, char p_den, char d_num, char d_den)
113. {
114. char string[6] = “\xBB”;
115. string[1] = max_speed;
116. string[2] = p_num;
117. string[3] = p_den;
118. string[4] = d_num;
119. string[5] = d_den;
120. serial_send_blocking(string,6);
121. }
122.
123. // stops the pid line following
124. void slave_stop_pid()
125. {
serial_send_blocking(“\xBC”, 1);
126. }
127.
128. // clear the slave LCD
129. void slave_clear()
130. {
serial_send_blocking(“\xB7”,1);
131.
}
132.
133. // print to the slave LCD
134. void slave_print(char *string)
135. {
136. serial_send_blocking(“\xB8”, 1);
137. char length = strlen(string);
138. serial_send_blocking(&length, 1); // send the string length
139. serial_send_blocking(string, length);
140. }
141.
142. // go to coordinates x,y on the slave LCD
143. void slave_lcd_goto_xy(char x, char y)
144. {
145. serial_send_blocking(“\xB9”,1);
146. serial_send_blocking(&x,1);
147. serial_send_blocking(&y,1);
148. }
149.
150. int main()
151. {
152. char buffer[20];
153. // load the bar graph
154. load_custom_characters();
155. // configure serial clock for 115.2 kbaud
156. serial_set_baud_rate(115200);
157.
158. // wait for the device to show up
159. while(1)
160. {
161. clear();
162. print(“Master”);
163.
delay_ms(100);
164.
serial_send(“\x81”,1);
165.
166. if(serial_receive_blocking(buffer, 6, 50))
167. continue;
168. clear();
169. print(“Connect”);
170. lcd_goto_xy(0,1);
171. buffer[6] = 0;
172. print(buffer);