My first Servo Program!!! with video - Thanks Guys
stevebzzzzz
Posts: 38
Here it is. Thanks for all the help...
PAUSE 1000
Position VAR Word 'Range of motion 300 to 1150
cw VAR Byte 'Clockwise 1 or 0
ccw VAR Byte 'Counter-Clockwise 1 or 0
Pulseduration VAR Word 'Pulsout duration
counter VAR Word 'Initialization Counter
cw = 0 'Initialize variables
ccw = 0
pulseduration = 750 'Center
'***** Center Servo
FOR counter = 1 TO 100
PULSOUT 14, Pulseduration
PAUSE 20
NEXT
DO 'Main Loop
IF IN0 =1 THEN 'If Button zero pressed
pulseduration = pulseduration - 50 'decrease pulse duration
ENDIF
IF IN4 = 1 THEN 'if Button four pressed
pulseduration = pulseduration + 50 'increase pulse duration
ENDIF
'Keep variables within boundries
IF pulseduration > 1150 THEN
pulseduration = 1150
ENDIF
IF pulseduration < 300 THEN
pulseduration = 300
ENDIF
'DEBUG HOME
'DEBUG ? IN0, CR
'DEBUG ? IN4, CR
'DEBUG ? pulseduration, CR
PULSOUT 14, pulseduration
PAUSE 20
LOOP UNTIL IN0=1 AND IN4=1 'Stop when both buttons are pressed
END
PAUSE 1000
Position VAR Word 'Range of motion 300 to 1150
cw VAR Byte 'Clockwise 1 or 0
ccw VAR Byte 'Counter-Clockwise 1 or 0
Pulseduration VAR Word 'Pulsout duration
counter VAR Word 'Initialization Counter
cw = 0 'Initialize variables
ccw = 0
pulseduration = 750 'Center
'***** Center Servo
FOR counter = 1 TO 100
PULSOUT 14, Pulseduration
PAUSE 20
NEXT
DO 'Main Loop
IF IN0 =1 THEN 'If Button zero pressed
pulseduration = pulseduration - 50 'decrease pulse duration
ENDIF
IF IN4 = 1 THEN 'if Button four pressed
pulseduration = pulseduration + 50 'increase pulse duration
ENDIF
'Keep variables within boundries
IF pulseduration > 1150 THEN
pulseduration = 1150
ENDIF
IF pulseduration < 300 THEN
pulseduration = 300
ENDIF
'DEBUG HOME
'DEBUG ? IN0, CR
'DEBUG ? IN4, CR
'DEBUG ? pulseduration, CR
PULSOUT 14, pulseduration
PAUSE 20
LOOP UNTIL IN0=1 AND IN4=1 'Stop when both buttons are pressed
END
Comments
One comment: you can make your posted code look nicer if you use the CODE tags, available on the Advanced posting screen (#). Here's what it would look like:
You're hooked now.
Duane