Line Sensor Code Problem

I have students who are using a 3 line tracker. The code they have written works for the right and left side, but the middle line sensor won’t work. I have double checked the ports and motor set-up. They are set up for line sensors. Here is the code that we have been using.

#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()
{

while(1==1){

if(SensorValue(button) == 0)
{
motor[leftmotor] = -127;
motor[rightmotor] = -127;

}

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

}

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

}

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

}
}

without more knowledge of the robot it’s difficult to make specific recommendations, however, make sure all sensors are plugged into the correct ports. test each line sensor using the sensors debug window to make sure the thresholds you have set are reasonable.

The while loop you have is going to execute extremely fast, there’s probably not time to allow the robot to steer correctly, it may detect the middle sensor but then also choose one of the other two as well. I would suggest adding a 100mS delay at the end of the loop.