I'm board so I figured I would clean up the code a little bit.
Code:
unsigned int turning = 0; /* Put at the top of user_routines.c just under the #includes. */
/* This code goes in the Default_Routine section of your user_routines.c file */
if (BUMP_SENSOR) /* If bump sensor evaluates to true then set turning to 40 */
{
turning = 40;
}
if (turning >= 35) /* Back up until expresson evaluates to false */
{
pwm01 = pwm02 = 70;
turning--; /* Deincraments the variable by 1 */
}
else if (turning) /* If turning is still true then turn until it evaluates to false */
{
pwm01 = 77; //assuming 2 motor drive train here
pwm02 = 187; //adjust values as necessary such as time needed to turn and turning speed
turning--; /* Deincraments the variable by 1 */
}
else
{
pwm01 = pwm02 = 200; /* If turning variable is false then go forward */
}
pwm02 -= 254; /* Reverses the direction of the oppsite motor */
/*
If statements:
If statements are code constructs that allow a programer to test an expresion.
The expression can either be true or false. A true expression is any number greater
than zero, while a false expresion is any number zero and below. One of the key
things to remember about an if statement is that only one snippet of code can be
executed per cycle. The other thing is that if statements have a higharcie of
testing.
Switches:
Switches are a code construct simular to an if statement except that is able to
execute multiple snipets of code in one cycle.
*/