Shop OBEX P1 Docs P2 Docs Learn Events
uhh yeah, how do i make a servo go backwards? — Parallax Forums

uhh yeah, how do i make a servo go backwards?

zemkaczzemkacz Posts: 19
edited 2007-11-01 22:42 in BASIC Stamp
this is what i have so far


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

time VAR Word
counter VAR Word

DO
GOSUB servo
GOSUB sensor_light
LOOP

servo:
IF time > 1000 THEN
  FOR counter = 1 TO 200
    PULSOUT 15, 5
  NEXT
    IF time < 1000 THEN
      FOR counter = 1 TO 200
        PULSOUT 15, 5
      NEXT
    ENDIF
ENDIF
RETURN

sensor_light:
HIGH 2
PAUSE 100
RCTIME 2, 1, time
DEBUG HOME, "time = ", DEC5 time
LOW 2
RETURN




now im usisng a light resitor for sensing light and using a servo to make it go back and forward, i got it going back when bright enought but it cant go forward, i have no idea on what i should use to make the servo reverse itself when it gets to dark.

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-11-01 22:42
    Move the first "ENDIF" after the "NEXT" -- as it is now, your "IF time < 1000 THEN" will always be 'false', because that only gets checked if "time" > 1000.

    Oh, and it would help to have a "MoveServo" subroutine:

    MoveServo:
    · PULSOUT 15, ServoVal
    · PAUSE 20
    · RETURN

    Then, set ServoVal to 750 (2 uSec per 'tick', 750 'ticks' * 2 uSec is 1.5 mSec, the centered 'pulse' value) for centered, 500 for full left, 1000 for full right -- or set ServoVal as appropriate, given your light-meter reading.
    ·
Sign In or Register to comment.