3 Line Sensor Problems

My students an I are working on 3 line sensors. We tried the new code given to me by the unofficial tech support, but are still having a problem of the left motors continually running. The following is the code we have modified to try and get it to work. Any ideas would be greatly appreciated!

#pragma config(Sensor, in1, leftlinesensor, sensorLineFollower)
#pragma config(Sensor, in3, rightlinesensor, sensorLineFollower)
#pragma config(Sensor, in4, middlelinesensor, sensorLineFollower)
#pragma config(Sensor, dgtl6, button, sensorDigitalIn)
#pragma config(Motor, port1, leftmotor, tmotorVex393_HBridge, openLoop, driveLeft)
#pragma config(Motor, port10, rightmotor, tmotorVex393_HBridge, openLoop, reversed, driveRight)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()



if(SensorValue(middlelinesensor) > 1000){
motor[leftmotor] = 100;
motor[rightmotor] = 100;


else if(SensorValue(leftlinesensor) > 1000){
motor[leftmotor] = 127;
motor[rightmotor] = 0;


else if(SensorValue(rightlinesensor) > 1000){
	motor[leftmotor] = 0;
	motor[rightmotor] = 127;


The problem is the approach to the if statements as relates to the motor calls. Presumably >1000 means the sensor has seen the line, and I’m assuming you properly labeled left and right. If the middle sensor sees the line, you go straight forward. Fine. If the left one sees it, then the robot is too far to the right, so you should turn left; but you are running the left motor forward and so turning right. And once you’ve then gone off the line, you shouldn’t see >1000 any more, so the motors will remain at 127 and 0 because no more if/else if’s will read a true value. This last bit isn’t a problem if you don’t leave the line, though. So swap your 127 and 0 in both of the else if statements, and you should be in good shape.

Thank you so much we will def try that next hour! This is my first year really working with the programming with kids so I am working through knowing how to set code up!