Shop OBEX P1 Docs P2 Docs Learn Events
Can anyone HELP ME with this coding — Parallax Forums

Can anyone HELP ME with this coding

EP7EP7 Posts: 4
edited 2008-07-11 19:13 in BASIC Stamp
'{$STAMP BS2}
'{$PBASIC 2.5}

DIR0 = 1
Holdbit VAR·· Bit
Start:
·· FREQOUT 0,1,38500
·· Holdbit = IN0
DEBUG 1, "sensor = ",DEC Holdbit, CR

DO
IF (IN0 = 0) THEN
PULSOUT 14, 1000
PAUSE 20
IF (IN0 = 1) THEN
PULSOUT 14, 100
PAUSE 20
ENDIF
ENDIF
LOOP
using this coding I get sensor response, but not any servo movement

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
THANKS,····· EP

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-10 00:24
    The IF statements are nested. When IN0 = 0, you put out a pulse, then check for IN0 = 1. If IN0 = 1, you never put out a pulse.
    Change the IF (IN0 = 1) THEN to an ELSE and eliminate one of the ENDIF statements
  • EP7EP7 Posts: 4
    edited 2008-07-11 18:37
    Using the help you gave me, now the servo will rotate in one direction and then hold,
    but the sensor/servo is not communicating·with each other and rotating the servo in opposite directions! any thoughts!

    I was also wondering what

    "DIR0" AND "Holdbit" means in the coding

    Thanks for the help mike!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    THANKS,····· EP
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-11 19:13
    1) DIR0 is the direction bit for pin 0 in the 16 bit direction register. It must be set to one (the default on power up) for that pin to work as an input.

    2) Holdbit is the name of a one bit variable that holds the state of the IR detector. You need to have "Holdbit = IN0" immediately after the FREQOUT because the IR detector will turn off (logic one) very quickly after the end of the FREQOUT.

    3) Along those lines, you should replace IN0 with Holdbit in the IF statement so the IF refers to the saved value rather than the current input pin value (which will always be one at that point).
Sign In or Register to comment.