View Single Post
  #3   Spotlight this post!  
Unread 30-12-2003, 15:00
echos's Avatar
echos echos is offline
Jack of all trades
#1125
Team Role: Programmer
 
Join Date: Dec 2003
Location: San Diego, CA
Posts: 61
echos will become famous soon enough
Send a message via ICQ to echos Send a message via AIM to echos Send a message via MSN to echos Send a message via Yahoo to echos
Re: hey need some help with writing a code please help me here

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.
 */