basic servo control question
ziggyrama
Posts: 1
Hi, I am sure this has been addressed before, but I haven’t had any luck finding an answer. I am trying to control a single servo and move it slowly from a stationary center position to a 90 degree position and hold it using a BS2 and an unmodified servo. I am using a standard FOR NEXT LOOP to move it, but cannot figure out how to leave the loop and keep the servo at 1250 once it reaches the final point. The servo simply pans back and forth between the two positions. I've tried using an IF statement to leave the loop, but it doesn't seem to work. Any help would be appreciated.
Thanks
for x = 750 to 1250 STEP 25
PULSEOUT 1,x
PAUSE 20
NEXT
Thanks
for x = 750 to 1250 STEP 25
PULSEOUT 1,x
PAUSE 20
NEXT
Comments
X VAR WORD
FOR x = 750 to 1250 step 25
ServoPos = x
GOSUB RefreshServo
NEXT
RefreshForever: ' Infinite loop, holding servo position...
GOSUB RefreshServo
GOTO RefreshForever
END
RefreshServo:
PULSOUT 1, ServoPos
Pause 20
RETURN
Doing the math, that means the code for moving the servo should be
FOR x=500 to 1000 step 25
Center position is PULSOUT 1,750