View Single Post
  #5   Spotlight this post!  
Unread 01-12-2004, 20:22
Rickertsen2 Rickertsen2 is offline
Umm Errr...
None #1139 (Chamblee Gear Grinders)
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2002
Location: ATL
Posts: 1,421
Rickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant future
Send a message via AIM to Rickertsen2 Send a message via Yahoo to Rickertsen2
Re: pwm ouput limiting

Quote:
Originally Posted by Joshua May
If I understand you correctly, then this should work. I can't remember the exact two-joystick code, but this concept should be valid.

Code:
if (p1_sw_top)
{
  pwm01 = p1_y + 4;
  pwm02 = p2_y + 4;
}
if (pwm01 > 138)
  pwm01 = 138;
if (pwm02 > 138)
  pwm02 = 138;
be careful. This won't work exactly as expected. The code above will increment the PWM value EVERY PROGRAM LOOP THAT THE BUTTON IS PRESSED FOR. While you may not press the button for very long, ALOT of program loops occur in this time and your pwm value will go haywire. To prevent this, you need to only increment once when the button is first pressed. An example of how to check if a button was jsut pressed goes somethign like the following:
Code:
int previous_Button_State = 0;

//check to see if the button was just pressed.
if (p1_sw_top & !previous_Button_State)
{
  //do stuff here
}
previous_Button_State = p1_sw_top;

Quote:
thanks for the help. by the way, I meant 238, not 138. (just stating that cause I feel dumb ) no matter, thanks for the help
I was a bit confused as to why you are limiting it that low.
__________________
1139 Alumni

Last edited by Rickertsen2 : 01-12-2004 at 20:27.