Shop OBEX P1 Docs P2 Docs Learn Events
Bs2 pushbutton servo control question? — Parallax Forums

Bs2 pushbutton servo control question?

EP7EP7 Posts: 4
edited 2008-07-03 17:53 in BASIC Stamp
Basically I want to use my BS2, a push-button which came with it, and a standard servo to rotate clockwise and then counterclockwise. unlike Activity 4 in the book "What's a Micro-controller" I only want to push, and not hold 1 push-button to control the servo to rotate both directions.· I was wondering if·someone could give me an example code to get started with! thanks for any help!· · ···EP


Here's·what I used, but it's not working for me! thanks again

'{$STAMP BS2}
'{$PBASIC 2.5}



· · · · counter· VAR· Word
· · · · duration VAR· Word
· · · · pulses···VAR· Word
· · · · loops· · VAR· Byte

'pulse' = pulse + 1
DEBUG ? IN3
DEBUG "Counterclockwise 12 o'clock", CR

IF IN3 = 1 THEN



FOR counter = 2 TO 200
· · PULSOUT 14, 1600
· · PAUSE 10

NEXT


DEBUG "Clockwise 6 o'clock",· CR

FOR counter = 2 TO 200
· · PULSOUT 14, 100
· · PAUSE 10
NEXT


DEBUG "All done."

ENDIF

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-03 17:53
    There are all sorts of things that need correcting here:
    1) The minimum pulse width for a servo is around 500us which would be a PULSOUT pin,250.
    For some servos, this would still be too short. Officially the minimum is 1000us (PULSOUT pin,500)

    2) The maximum pulse width for a servo is around 2500us which would be a PULSOUT pin,1250.
    For some servos, this would still be too long. Officially the maximum is 2000us (PULSOUT pin,1000)

    3) For checking a pushbutton, sometimes the BUTTON statement is used. There's a whole chapter in the manual on this with examples.
    In your case, you're only checking the button once, then your program stops. If the button isn't pushed when your program finishes the DEBUG statement, that's it. Usually you have a loop that repeatedly checks for a button push, then waits for the button to be released (so, if you hold the button down too long, it doesn't look like multiple button pushes). The BUTTON statement takes care of all of this. Example:
    DO 
       IF IN3 = 1 THEN ' Check for button pushed
          ' < perform some task>
       ENDIF
       DO UNTIL IN3 = 0 ' Wait for button to be released
       LOOP
    LOOP
    


    4) The delay between servo pulses is more like 20ms. 10ms might work ok, but closer to 20ms is better.
Sign In or Register to comment.