Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By heckler
#62018 Hey Group,

In my Servo Test program I would like to change the range for the SLIDER...

Code: Select allslider Servo,LL,RL


full test program...
Code: Select allcls
let pinNo = 2
let Servo = 0
let LL = 0
let RL = 180

wprint "Control PIN "
textbox pinNo
html "<BR>"
wprint "Left Limit = "
textbox LL
html "<BR>"
wprint "Right Limit = "
textbox RL
html "<BR>"
html "<BR>"
wprint " Servo Now = "
textbox Servo
button " Set Servo",[SetServo]
slider Servo,LL,RL
'timer 200,[SetServo]
html "<BR>"
html "<BR>"
button " Exit ", [TestExit]
wait

[SetServo]
io(servo,pinNo,Servo)
wait

[TestExit]
io(servo,pinNo,0)
end


In my test code above I am trying to accomplish this by utilizing text boxes but it does not have the desired effect.

However the text box that allows me to choose the output pin does work as expected.

Can anyone help me to understand how to change the limits of the SLIDER function within my program?
Either with the TEXTBOX or some other way.
thanks in advance
dwight
Last edited by heckler on Sat Feb 04, 2017 1:40 pm, edited 1 time in total.
User avatar
By Electroguard
#62022 You've got some typo's...

let RR = 180

should be... RL (cos that's what you are referencing later).


The [SetServo] branch contains an incorrect 'io(servo,pinNo,Servo)'... you need to change the first "servo" references to PWO (and similarly in the [TestExit] branch.
User avatar
By heckler
#62025 Thanks Electroguard,

You are right about the typo on RL = 180 (I corrected the test code in my first post)

but there actually is an io(servo,pin,value) function.
Servos need a pwm signal that repeats at 50Hz whereas the pwm function outputs the signal at a much quicker rate and has a wider range.

Also servos need the pwm width to be in a range of 1.0 to 2.0 ms which is equivalent to 0 to 180 degrees (roughly)

so the VALUE in io(servo,pin,value) should be within 0-180 (see docs)

I would like to modify the range that the slider provides such that if one is testing a servo connected to a system where you don't want it to swing the full 0-180 range then one could input new limits (RL and LL) to prevent over travel. And then have the SLIDER take on the new Left and Right limits.

Possibly I need to modify my test program so that you have to enter the RL and LL values before it continues on to the SLIDER statement.

Is the only way to enter values from the web page to the code through the use of TEXTBOX or is there a better way??

thanks
dwight
User avatar
By Electroguard
#62028 Yeah, I was testing using LED brightness instead of a servo.

I think that once you've defined the slider it's going to be a done deal, so changing the limit vars afterwards is probably not going to be able to affect the slider.

I would probably set up the required limits at the top of the program, then drop through a branch - eg: [HOME] - then cls and define the slider according to the defined limits.
Then if you wish to subsequently redefine the slider limits you can goto [HOME] and redisplay a redefined and re-drawn slider with the new limits.