Revision 1945
Changed to use Alex's barcode code.
lineFollow.c | ||
---|---|---|
281 | 281 |
|
282 | 282 |
|
283 | 283 |
// new version by Alex |
284 |
/*void updateBarCode()
|
|
284 |
void updateBarCode() |
|
285 | 285 |
{ |
286 |
// Average the readings of the last 2 sensors |
|
287 |
int curReading = (read_line(6) + read_line(7)) / 2; |
|
288 |
int curColor = (curReading > 500) ? LBLACK : LWHITE; |
|
289 |
|
|
290 | 286 |
// USING THESE GLOBAL VARIABLES |
291 | 287 |
// global int duration = 0; |
292 | 288 |
// global int lastColor = 0; |
293 | 289 |
// global int barCodePosition = 0; |
294 | 290 |
// global char isReset = 0; |
295 | 291 |
|
292 |
// Average the readings of the last 2 sensors |
|
293 |
if(read_line(6) - read_line(7) > 150 || read_line(6) - read_line(7) < -150) |
|
294 |
{ |
|
295 |
return; |
|
296 |
} |
|
297 |
|
|
298 |
int curReading = (read_line(6) + read_line(7)) / 2; |
|
299 |
int curColor; |
|
300 |
|
|
301 |
if(curReading > BLACK_THRESHOLD) |
|
302 |
curColor = LBLACK; |
|
303 |
else if(curReading < GREY_THRESHOLD) |
|
304 |
curColor = LWHITE; |
|
305 |
else |
|
306 |
curColor = LGREY; |
|
307 |
|
|
296 | 308 |
// Just an error check |
297 | 309 |
if(barCodePosition > CODESIZE) |
298 | 310 |
{ |
299 | 311 |
barCodePosition = 0; |
300 | 312 |
} |
301 | 313 |
|
314 |
// We are only interested in consecutive color values |
|
302 | 315 |
if(curColor == lastColor) |
303 | 316 |
{ |
304 | 317 |
duration++; |
... | ... | |
317 | 330 |
if(isReset && (curColor == LBLACK || curColor == LGREY) ) |
318 | 331 |
{ |
319 | 332 |
isReset = 0; |
333 |
usb_puts("Read barcode bit: "); |
|
334 |
usb_puti(barCodePosition); |
|
335 |
usb_puts(" = "); |
|
336 |
usb_puti(curColor); |
|
337 |
usb_puts(", curReading = "); |
|
338 |
usb_puti(curReading); |
|
339 |
usb_puts(".\n"); |
|
320 | 340 |
|
321 | 341 |
barCode[barCodePosition++] = (curColor == LBLACK) ? 1 : 0; |
322 | 342 |
} |
... | ... | |
325 | 345 |
isReset = 1; |
326 | 346 |
} |
327 | 347 |
} |
328 |
}*/ |
|
348 |
if(duration > TIMEOUT_DURATION && barCodePosition != 0) |
|
349 |
{ |
|
350 |
usb_puts("TIMED OUT. BARCODE READER RESET.\n"); |
|
351 |
barCodePosition = 0; |
|
352 |
duration = 0; |
|
353 |
} |
|
354 |
} |
|
329 | 355 |
|
330 |
|
|
331 |
void updateBarCode() |
|
356 |
// Dan's version |
|
357 |
/*void updateBarCode()
|
|
332 | 358 |
{ |
333 | 359 |
//! Note: currently only uses one of the barcode sensors. |
334 | 360 |
|
... | ... | |
366 | 392 |
} |
367 | 393 |
else countHi/=2; |
368 | 394 |
if(countHi==0)countLo=0; |
369 |
} |
|
395 |
}*/
|
|
370 | 396 |
|
371 | 397 |
|
372 | 398 |
int min(int x, int y){return x>y ? y : x;} |
Also available in: Unified diff