Asked
— Edited
Resolved by Rich!
So Im trying to use use a slide script. I have the variable setup as $RightPWM. If I want to make another script that uses that variable to set the pwm how would I do that? Aka $RightPWM= 5, I want the pwm to change to 5. How would I do this? If statement? Not sure how I would make it.
Assuming the port is D0 the command would be;
You will need to make sure $RightPWM is set to something before running the script or command which uses the variable though otherwise it will error as the variable will not exist. I usually add all variables to an init script and set them to 0, this ensures the variables exist and will avoid any scripts failing due to the possibility of an error.
thanks rich. is there a way to make it so its always one more than the variable?
I don't see the point in that, that's the whole idea of a variable but yes.
Ok thanks. My method is that is if the pwm needs to be 0, and the minimum value for the variable is 1, I guess I could run the pwm one less to successfully stop the motor. Sorry if I'm not making sense lately. Not sure what's gotten into me.
Slide Script allows a minimum value of 0 and maximum of 1000 and is configurable. If you set it from 0 to 100 and use the variable for a PWM command it should be exactly the same as adding the PWM control (which therefore makes the whole idea of using the slide script for PWM redundant since you could use the control already available).
What is it you are trying to achieve? There may be a better/different method.
Its possible im going to run other scripts based of the variable so I just thought id get it sorted out.
You could always use the GetPWM() command to run other scripts based on the PWM of the port...
or a WaitForChange() and a GetPWM()
Either way will work, using a slide script or using a PWM control, I always prefer to use the native controls over scripting when possible, they are there to make things easier.