
PsionicCylon
USA
Asked
— Edited
Is there any way to set a servo value in a loop without running it in another script window? When I try to set a servo value in Goto loop, it only runs once. When I use multiple windows, the servo doesn't always update to the new value. Here is the script from my main window, it takes a potentiometer value, does some math, then starts a window that sets a servo to that value.
:Start
Release(D7)
$PotCurrent = GetADC(adc0)
$ServoValue = $PotCurrent / (189 / 81) - 25
ControlCommand("SetServo",scriptStart)
Goto(Start)
Then here is the other window.
$ValueServo = $ServoValue
Servo(D7,$ValueServo)
Not having that first line gives an error about setting servo positions to variables.
Please help!
Why not do it in one script? What you have won't work because it's multithreaded. You'd want to use the ScriptStartWait command...
Or if you insist on doing it your suggested way
Well, I copied and pasted this code and it only ran once. When you do anything to a servo, Goto loops don't work, they run only once. The only way I could get it to work was what I pasted above, and it ran very slowly.
That's not true. I didn't notice when I edited your code that the release statement is there lol. If you release a servo, it's not going to move. Take the release out. Picture what that loop was doing. Move servo but 1 ms later release it. So it never ends up moving at all
Also I'd put a sleep in there for 100ms or so. I'm on my iPhone so no code samples, you can figure it out I bet
Updated above code samples