My team is currently using Vexcode IQ Blocks and are having problems trying to get the robot to stop at a black line. We are able to stop at a white line using the code we made. We tried to reverse the sign from greater than to less than and the program does not do anything. Along with that we tried many different loops and other ways of reordering the stop and forward for the motors
If there’s any help we can get it would greatly be appreciated. Thank you.
What you can do is create a variable that when you detect the line, you set it to a different value. Then, use a while loop that runs while the variable is equal to what you originally set it to be. That way, you end the loop.
You should either do the while loop or do the forever loop with an if-statement and a break. Don’t do both. Essentially, you are ending the loop after the code runs once.
I tried both solutions and if I put in a greater than sign it’ll go forward forever, but if I have a less than sign it will skip over everything. Color Sensor Test (1).pdf (2.7 MB) Color Sensor Test (2).pdf (2.2 MB)
In your first example, the break is outside the condition if statement, so it breaks straight away and the robot never stops. Try moving break inside the if directly under the motor stops.
For the while loop, you should say:
While colour > threshold
Drivefoward
Then outside the loop, stop the motors.
The colour sensor brightness value is greater on a whiter surface isnt it? So while it is greater than your black threshold (i.e. on white), drive forward.