Marble Sorting Machine Help?

Hi, I’m working on making a marble sorting machine in my Sophomore engineering class that uses a light sensor to differentiate between three different marbles, but there’s a problem; I can get the marbles to be detected and can get my servo motor to spin to a certain position depending on the type of marble, but I can’t get the Servo to REMAIN in that position, so I need to know, what command(s) would I have to use to make it stay in that position whilst the marble is pushed and rolled into it?

Here is my code:

task main()
{
turnFlashlightOn (flashlight, 127)
while (1==1)
if (SensorValue (lightSensor) < 250 )
setservo(port2, 127)
else
if (SensorValue (lightSensor) > 700)
setservo(port2, -127)
else
if (SensorValue (lightSensor) > 250)
setservo(port2, 0)
}

Any help would be appreciated, thanks in advance!

I don’t know if this is your problem but doesn’t the while loop need {} and the end of each statement needs ;

task main()
{
turnFlashlightOn (flashlight, 127);
while (1==1)
{
if (SensorValue (lightSensor) < 250 )
setservo(port2, 127);
else
if (SensorValue (lightSensor) > 700)
setservo(port2, -127);
else
if (SensorValue (lightSensor) > 250)
setservo(port2, 0);
}
}

1 Like

There r no semicolons in ur code