Shop OBEX P1 Docs P2 Docs Learn Events
My first Servo Program!!! with video - Thanks Guys — Parallax Forums

My first Servo Program!!! with video - Thanks Guys

stevebzzzzzstevebzzzzz Posts: 38
edited 2011-07-19 13:11 in BASIC Stamp
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

Comments

  • sylvie369sylvie369 Posts: 1,622
    edited 2011-07-19 13:02
    Nice. It's fun to do something with such visible results, isn't it?

    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:
    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
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-07-19 13:11
    And you probably thought the LEDs were fun.

    You're hooked now.

    Duane
Sign In or Register to comment.