Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. task main()
  2. {
  3. int lowIR = 1000; //Arbitrary high number so the calibration will work
  4. int highIR = 0;
  5.  
  6. //Auto-calibration ended by button press. The button will begin the line following.
  7. //During this time, the robot should be moved so that it sees both black and white -
  8. //you could 'scan' it across the line.
  9. while(!SensorValue[button]) {
  10. if(SensorValue[centerIR] > highIR) {
  11. highIR = SensorValue[centerIR];
  12. } else if(SensorValue[centerIR] < lowIR) {
  13. lowIR = SensorValue[centerIR];
  14. }
  15. }
  16.  
  17. //Set threshold as the average of light and dark.
  18. int threshold = (lowIR + highIR) / 2;
  19.  
  20. // Light following loop
  21. while(true)
  22. {
  23. // RIGHT sensor sees dark:
  24. if(SensorValue(rightIR) > threshold)
  25. {
  26. // counter-steer right:
  27. motor[leftServo] = 40;
  28. motor[rightServo] = 0;
  29. }
  30. // CENTER sensor sees dark:
  31. if(SensorValue(centerIR) > threshold)
  32. {
  33. // go straight
  34. motor[leftServo] = 40;
  35. motor[rightServo] = 40;
  36. }
  37. // LEFT sensor sees dark:
  38. if(SensorValue(leftIR) > threshold)
  39. {
  40. // counter-steer left:
  41. motor[leftServo] = 0;
  42. motor[rightServo] = 40;
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement