View Single Post
  #6   Spotlight this post!  
Unread 02-12-2004, 08:39
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,855
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: pwm ouput limiting

Here’s a variation.
If you mean to increase the top joystick speed (originally 238) by 4 every time the button is pushed then you’ll need to preserve the last known value. Expanding on the Joshua and James examples (but only looking at one of the joysticks to simplify):
Code:
static unsigned char rightTopSpeed=238;
static char previous_top_Button_State = 0, previous_trig_Button_State = 0; //FALSE
 
if (p1_sw_top & !previous_top_Button_State)
{
	if (rightTopSpeed < 251) // Limit how high it can go
	{
		rightTopSpeed+= 4;
	}
	previous_top_Button_State = p1_sw_top;
}
 
// You might want to be able to decrement as well
else if (p1_sw_trig & !previous_trig_Button_State) 
{
	if (rightTopSpeed > 238) // Limit how low it can go
	{
		rightTopSpeed-= 4;
	}
	previous_trig_Button_State = p1_sw_trig;
}
 
if (pwm01 > rightTopSpeed)
	pwm01 = rightTopSpeed;
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 02-12-2004 at 13:23. Reason: Changed check from 254 to 251 --Thanks to Greg