Quote:
|
Originally Posted by NNSWIZ
I have a problem with my autonomous code. It involves the use of a lot of while() loops that the compiler says will not end. I heard you might have to put an extra condition in the loop such as "If the motor is not on..."(In code). Here's my code:
while (rightteeth < 4 || leftteeth < 4)/*if robot has not turned four gear tooth counts... */
{
pwm13 = 0; /*rev left motor */
pwm15 = 255; /*forward right motor, hopefully will turn robot about ten deg's */
}
The variables rightteeth and leftteeth are to count inputs from the hall effect sensors.
Please someone help me!
|
The compiler is definately right...
You are incorrectly using the while loop. Since you never increment rightteeth or leftteeth inside the loop, it will loop forever This will have the side effect of having your robot run at whatever speed it was running before the loop was hit. This is because the outputs are set at the bottom of the main loop, which will never get hit in your case.
What you probably want to do is use an IF case. The main loop will take care of the iteration.