Need help with a program that reads an input
paulm81
Posts: 7
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
' {$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
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.
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
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