I'm trying to write a program using BASIC to turn a servo 180 degrees back and forth, and to use a potentiometer to control the speed at which the servo turns. I have a code, but when I run it, the servo freaks out and starts twitching in one spot, and I don't know why it's doing that or what's causing it. Can someone explain to me why it's doing that, what's causing it, or a way to fix it?
' What's a Microcontroller - ControlServoWithPotUsingDirectives.bs2
' Read potentiometer in RC-time circuit using RCTIME command.
' Apply scale factor and offset, then send value to servo.
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
rcPin PIN 5 ' I/O Pin Definitions
servoPin PIN 14
scaleFactor CON 15 ' Constant Declarations
offset CON 1
delay CON 10
time VAR Word ' Variable Declaration
PAUSE 1000 ' Initialization
DO
' Main Routine
HIGH rcPin ' RC decay measurement
PAUSE 100
RCTIME rcPin, 1, time
'time = time * scaleFactor ' Scale scaleFactor.
'time = time + offset ' Offset by offset.
'PULSOUT servoPin, time ' Send pulse to servo.
'DEBUG HOME, DEC5 time ' Display adjusted time value.
FOR counter = 300 TO 1100 STEP time
PULSOUT servoPin, counter
PAUSE 7
DEBUG DEC5 counter, CR
DEBUG DEC5 time, CR
NEXT
PAUSE 10
FOR counter = 1100 TO 300 STEP time
PULSOUT servoPin, counter
PAUSE 7
DEBUG DEC5 counter, CR
DEBUG DEC5 time, CR
NEXT
LOOP