Shop OBEX P1 Docs P2 Docs Learn Events
Need help with a program that reads an input — Parallax Forums

Need help with a program that reads an input

paulm81paulm81 Posts: 7
edited 2009-10-01 17:35 in BASIC Stamp
Hi folks I need some help with a program that reads the status of pin3 and if the pin is high it gosbs to a routine to make the pololu dual micro serial controller go in reverse. And when the pin3 goes low gosub to a routine to make the controller go forward. help

' {$STAMP BS2}
' {$PBASIC 2.5}
INPUT 3
pin3stat VAR Bit
pin3stat = IN3
timer VAR Word
HIGH 0
LOW 2
HIGH 2
PAUSE 100
DO
SEROUT 0,84, [noparse][[/noparse]$80, 0, 6,0]
SEROUT 0,84, [noparse][[/noparse]$80, 0, 0,0]
IF pin3stat = 1 THEN GOSUB mvfwd
ENDIF
IF pin3state = 0 THEN GOSUB mvback
ENDIF
mvfwd:
SEROUT 0,84, [noparse][[/noparse]$80, 0, 6,100]
SEROUT 0,84, [noparse][[/noparse]$80, 0, 0,100]
FOR timer = 0 TO 2000
NEXT

mvback:
SEROUT 0,84, [noparse][[/noparse]$80, 0, 1,100]
SEROUT 0,84, [noparse][[/noparse]$80, 0, 3,100]
FOR timer = 0 TO 2000
NEXT
SEROUT 0,84, [noparse][[/noparse]$80, 0, 1,0]
SEROUT 0,84, [noparse][[/noparse]$80, 0, 3,0]
LOOP

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-01 16:15
    1) When you say you need help, you need to be specific about your problem. What error messages are you seeing? ... What kind of unexpected behavior are you observing or measuring?

    2) There's one obvious syntax problem. The IF statement has two forms ...

    IF <expression> THEN
    <statements>
    ENDIF

    or

    IF <expression> THEN <statement>

    You're combining the two and that won't work. Pick one or the other. Consult the Stamp manual or Stamp Editor help files regarding the IF statement for details.
  • paulm81paulm81 Posts: 7
    edited 2009-10-01 16:37
    What would be the simplest way to program the bs2 that when input 3 is high send this command
    SEROUT 0,84, [noparse][[/noparse]$80, 0, 6,0]
    SEROUT 0,84, [noparse][[/noparse]$80, 0, 0,0]
    to serial controller. And when the input 3 goes low send this command
    SEROUT 0,84, [noparse][[/noparse]$80, 0, 1,100]
    SEROUT 0,84, [noparse][[/noparse]$80, 0, 3,100]

    thanks
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-01 16:43
    1) You need to go through the "What's a Microcontroller?" tutorial that you can download from Parallax. It will teach you Stamp Basic (PBasic). You also need to have a copy of the Basic Stamp Syntax and Reference Manual on hand which you can also download.

    2)
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    DO
    IF IN3 = 1 THEN
    SEROUT 0,84, [noparse][[/noparse]$80, 0, 6,0]
    SEROUT 0,84, [noparse][[/noparse]$80, 0, 0,0]
    ELSE
    SEROUT 0,84, [noparse][[/noparse]$80, 0, 1,100]
    SEROUT 0,84, [noparse][[/noparse]$80, 0, 3,100]
    ENDIF
    LOOP
  • paulm81paulm81 Posts: 7
    edited 2009-10-01 17:35
    thank you
Sign In or Register to comment.