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;