Posted by Charles Elwood.
Engineer on team Bees from Morrisstown High School sponsored by IPT.
Posted on 2/2/2000 8:47 PM MST
I have a question. Suppose I have a motor attached to PWM1 and when you push the joystick on Port1 forward, the motor moves clockwise…okay now suppose I add some code so that when I push the joystick forward the motor will now move in the opposite direction.
Thanks
charles Elwood
Posted by Jerry Eckert.
Engineer from Looking for a team in Raleigh, NC sponsored by .
Posted on 2/2/2000 10:22 PM MST
In Reply to: programming posted by Charles Elwood on 2/2/2000 8:47 PM MST:
: I have a question. Suppose I have a motor attached to PWM1 and when you push the joystick on Port1 forward, the motor moves clockwise…okay now suppose I add some code so that when I push the joystick forward the motor will now move in the opposite direction.
: Thanks
: charles Elwood
pwm1 = 254 - pwm1
Posted by Joe Johnson. [PICTURE: SAME | NEW | HELP]
Engineer on team #47, Chief Delphi, from Pontiac Central High School and Delphi Automotive Systems.
Posted on 2/3/2000 4:46 AM MST
In Reply to: Re: programming posted by Jerry Eckert on 2/2/2000 10:22 PM MST:
OR…
You could just reverse the wires going from the Victor to the motor.
Depends on what you want to do. If you want to see code examples that is one thing. If you really just want to reverse the direction of the motor, flipping the wires is easy too.
Joe J.
P.S. You MAY want to put a few more bits of code in the example given in the message by Jerry Eckert, depending on how paranoid you are about problems with PBasic’s 16 bit unsigned math.
I would perhaps write it like this:
pwm1 = 254 - (pwm1 max 254)
This will prevent pwm1 from going wacko if it ever happens to be set to 255 going into the conversion. Also, while I am at it, do NOT do this:
pwm1 = (254 - pwm1) min 0
This will not work as desired. In PBasic, NOTHING is less than 0 so the expression ‘XXX min 0’ ALWAYS returns XXX. Pbasic has some strange ideas when it comes to math…