Thread: loop problems
View Single Post
  #7   Spotlight this post!  
Unread 10-02-2006, 13:03
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: loop problems

Quote:
Originally Posted by Max Brin
Hey guys,

I had some problems using the timers and I need something that will take time asap, so I did this:

Code:
void pulse(void)
{
pwm06=255;
for (int i=0;i<30;i++)
	{
	if (i == 29)
		{
		pwm06=127;
		}
	}
}
It means the pwm06 will get 255 and when it gets to 29 it will stop.
It will take about 0.5 second right?
anyways I get a syntax error, can somebody help me?

Thanks!
syntax error is caused by trying to declare i in the for loop
in C all variables must be declared at the top of the function.

This still will not do what you want because the pwm value is not sent out until Putdata is called. (see user_routines.c )

One way to accomplish what you want is to use a static counter variable. Increment each time the function is called. When the desired value is reached, change the pwm value and reset the counter variable.