Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- task main()
- {
- int lowIR = 1000; //Arbitrary high number so the calibration will work
- int highIR = 0;
- //Auto-calibration ended by button press. The button will begin the line following.
- //During this time, the robot should be moved so that it sees both black and white -
- //you could 'scan' it across the line.
- while(!SensorValue[button]) {
- if(SensorValue[centerIR] > highIR) {
- highIR = SensorValue[centerIR];
- } else if(SensorValue[centerIR] < lowIR) {
- lowIR = SensorValue[centerIR];
- }
- }
- //Set threshold as the average of light and dark.
- int threshold = (lowIR + highIR) / 2;
- // Light following loop
- while(true)
- {
- // RIGHT sensor sees dark:
- if(SensorValue(rightIR) > threshold)
- {
- // counter-steer right:
- motor[leftServo] = 40;
- motor[rightServo] = 0;
- }
- // CENTER sensor sees dark:
- if(SensorValue(centerIR) > threshold)
- {
- // go straight
- motor[leftServo] = 40;
- motor[rightServo] = 40;
- }
- // LEFT sensor sees dark:
- if(SensorValue(leftIR) > threshold)
- {
- // counter-steer left:
- motor[leftServo] = 0;
- motor[rightServo] = 40;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement