How can i program a joystick trigger to scale down the speed of a motor:confused:
That would be difficult, it’s either on or off… so you could turn the motor on or off…
unless you want to try funky pattern timing…
perhaps he meant scale the speed.
Ex: if you have a really fast robot, maybe you want to scale the speed down to 3/4 of full speed for more control. I think he is talking about using the trigger to do something like this. I know we did this for some odd reason at Cal Games, but I dont know jack about programming, so I cant help you.
Cory
You could key off of the trigger to indicate the addition or subtraction of a fixed value (1,5,10) to a pwm output.
Initialize to a pwm output of neutral (127). Then, you’ll need a direction bit (fwd/rev) so you know whether to add or subtract, and a trigger latch bit so you don’t loop through the code a bunch of times, changing the pwm, before you let go of the trigger. You’ll also want to min and max (1, 254) so you don’t roll over.
Or set a static entry if you just want to tone it down to 3/4 or total or whatnot… Then just hit trigger and get 3/4 speed ahead, interesting actually… hmmm.
Yeah, you could have it that every x amount of loops it adds 5 to the PWM input. About 30-40 program loops is a second.
Just use PWM = PWM + 5 MAX 250 so you don’t wrap around.
The other option is to have it turn on or off. This is more limited, but easier to deal with.
I’m interperting your request as if you have a joystick, and you want to be able to press a button on it to slow down the robot, in order to make it more controllable.
If this is what you’re looking for insert this write after the code block where you tie the p1_y and p1_x (or whatever vars you use) to the pwms:
if (p1_top = 1) then
if pwm1 > 127 then pwm1 = (pwm1-127) / 2 + 127
if pwm1 < 127 then pwm1 = (127 - (127-pwm1) / 2)
endif
Do the same for pwm2. This will reduce the speed of the robot by a factor of 2 when p1_top is pressed.