Slider$

All that relates to Javascript, CSS, HTML, ....
Post Reply
andywong
Posts: 13
Joined: Wed Mar 01, 2023 10:05 pm
Has thanked: 2 times

Slider$

Post by andywong »

Hi, I am new to Annex RDS.
I was trying to get the value of the variable sv in the following line as an example:
Slider$(sv,0,180)
All I got was the value 0; but the servo did move correctly. What is my mistake?

My code:
R = 12
sv = 0
servo.setup 1, R

html "Servo Angle => "
html "<cr>"
html "0 "
html slider$ (sv,0,180)
html " 180"
html " "
html sv 'Report the value of sv

loop1:
servo 1, sv
goto loop1
wait
end
bugs
Posts: 142
Joined: Mon Feb 08, 2021 10:10 pm
Location: Scotland
Has thanked: 44 times
Been thanked: 50 times

Re: Slider$

Post by bugs »

Hi,

I am not an expert but this modified example may help.
Use a textbox to automatically display a variable when the html is refreshed.
There are better ways without using a loop but this might be a quick fix...

Code: [Local Link Removed for Guests]

R = 12
sv = 0
servo.setup 1, R

html "Servo Angle => "
html textbox$(sv) 'Report the value of sv
html "<br>"
html "0 " & slider$ (sv,0,180) & " 180"

loop1:
  servo 1, sv
  refresh
goto loop1

end
User avatar
cicciocb
Site Admin
Posts: 1900
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1271 times
Contact:

Re: Slider$

Post by cicciocb »

Following the suggestion given by Bugs, this is my proposal :

Code: [Local Link Removed for Guests]

R = 12
sv = 0
servo.setup 1, R
gosub myPage 'load the web page at the first run
onHtmlReload myPage 'reload the web page automatically
while 1
  servo 1, sv
wend

myPage:
cls
html "Servo Angle => "
html textbox$(sv) 'Report the value of sv
html "<br>"
html "0 " & slider$ (sv,0,180) & " 180"
autorefresh 250  'refresh automatically the variables each 250msec
return 

end

User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: Slider$

Post by Electroguard »

In addition to the help from Bugs and Francesco you might find some useful info in this servo project which uses web sliders to control pan and tilt...
[Local Link Removed for Guests]
andywong
Posts: 13
Joined: Wed Mar 01, 2023 10:05 pm
Has thanked: 2 times

Re: Slider$

Post by andywong »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sun Mar 26, 2023 9:49 am Following the suggestion given by Bugs, this is my proposal :

Code: [Local Link Removed for Guests]

R = 12
sv = 0
servo.setup 1, R
gosub myPage 'load the web page at the first run
onHtmlReload myPage 'reload the web page automatically
while 1
  servo 1, sv
wend

myPage:
cls
html "Servo Angle => "
html textbox$(sv) 'Report the value of sv
html "<br>"
html "0 " & slider$ (sv,0,180) & " 180"
autorefresh 250  'refresh automatically the variables each 250msec
return 

end

I tried your code. I am still getting value 0; but servo did moved correctly. But if I added refresh inside the while loop. It worked. Thank you.
It also work if I add onHtmlChange myPage at the beginning of the program.
Last edited by andywong on Mon Mar 27, 2023 11:01 am, edited 3 times in total.
andywong
Posts: 13
Joined: Wed Mar 01, 2023 10:05 pm
Has thanked: 2 times

Re: Slider$

Post by andywong »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sun Mar 26, 2023 9:28 am Hi,

I am not an expert but this modified example may help.
Use a textbox to automatically display a variable when the html is refreshed.
There are better ways without using a loop but this might be a quick fix...

Code: [Local Link Removed for Guests]

R = 12
sv = 0
servo.setup 1, R

html "Servo Angle => "
html textbox$(sv) 'Report the value of sv
html "<br>"
html "0 " & slider$ (sv,0,180) & " 180"

loop1:
  servo 1, sv
  refresh
goto loop1

end
Thank you, It worked.
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 253 times
Been thanked: 128 times

Re: Slider$

Post by Zim »

Code: [Local Link Removed for Guests]

onHtmlReload myPage
onhtmlchange myPage
sv = 0
R = 0
servo.setup 1, R
gosub myPage 
wait

myPage:
cls
servo 1, sv
html "Servo Angle => "
html textbox$(sv) 'Report the value of sv
html "<br>"
html "0 " & slider$ (sv,0,180) & " 180"
autorefresh 250 'refresh automatically the variables each 250msec
return 

end
andywong
Posts: 13
Joined: Wed Mar 01, 2023 10:05 pm
Has thanked: 2 times

Re: Slider$

Post by andywong »

Thankyou, it works!
andywong
Posts: 13
Joined: Wed Mar 01, 2023 10:05 pm
Has thanked: 2 times

Re: Slider$

Post by andywong »

Thankyou, it works!
[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Mon Mar 27, 2023 9:44 am Thankyou, it works! Good example.
Post Reply