Hi,
What change should I make to my PBASIC default code to manifulate how fast a motor goes from 127 to 0, or from 127 to 254.
Thanx
If you want to make the motor go faster, you are out of luck.
If you want to make it go slower, you just have to reduce the distance away from 127 to make the voltage to the motor less.
Code below (untested off the top of my head so it may have bugs, but I think it is good to go). Also, I have resigned myself to the fact that pbasic has a certain order of operations and that that order is not the order you and I normally use. Some folks use parenthesis to try to fix this problem. The intent is to make matters clear to the reader, but in fact, in the case of pbasic, they make matters UNCLEAR, so I use them as little as I can. I am much happier this way. You should try it. It is okay… …really.
Pbasic Zen Master,
Joe J.
MotorPWM Var Byte
ScaleNum CON 4
ScaleDen CON 4
'Total scalefactor = ScaleNum / 2^ScaleDen
'Example above Scalefactor = 0.25 or 25%
'Set MotorPWM as usual
if MotorPWM < 127 ScaleReverse
ForwardScale:
MotorPWM = MotorPWM - 127 * ScaleNum >> ScaleDen + 127 MAX 254
goto ScaleDone
ScaleReverse:
MotorPWM = 127 - (127 - MotorPWM * ScaleNum >> ScaleDen MAX 127)
ScaleDone:
'continue coding…
'if you want to have an adustable “gas” you can replace ScaleNum with a variable (p1_wheel for example) Joe J