converting BS2 code to BS1
Matthew
Posts: 200
So I·recently made a simple code a BS2. Now I'm trying to translate it so the BS1 can understand it. But one problem arises, the BS1 doesn't understand 'elseif' commands.
Pretty much the program is monitoring 2x push-down/push-up buttons, and depending on which configuration it sees (only 4 different kinds) it will turn a continuous rotating servo either clockwise or counterclockwise.
Here's my code, any help would be greatly apreciated:
'
[noparse][[/noparse] Title ]
' What's a Microcontroller - String Aligner 1.bs2
' String Aligner 1
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Declarations ]
'
[noparse][[/noparse] Initialization ]
direction VAR Bit
'
[noparse][[/noparse] Main Routine ]
DO
· GOSUB Check_Switches
· GOSUB Turn_Servo
· GOSUB Display
LOOP
'
[noparse][[/noparse] Subroutines ]
Check_Switches:
IF (IN1=0) AND (IN2=0) THEN
direction=0
ELSEIF (IN1=0) AND (IN2=1) THEN
direction=1
ELSEIF (IN1=1) AND (IN2=1) THEN
direction=0
ELSEIF (IN1=1) AND (IN2=0) THEN
direction=1
ENDIF
RETURN
Turn_Servo:
IF direction=0 THEN
· PULSOUT 14, 1000
· PAUSE 18
ELSEIF direction=1 THEN
· PULSOUT 14, 500
· PAUSE 18
ENDIF
RETURN
Display:
IF direction=1 THEN
DEBUG HOME, "Turning right"
ELSEIF direction=0 THEN
DEBUG HOME, "Turning left "
ENDIF
RETURN
Pretty much the program is monitoring 2x push-down/push-up buttons, and depending on which configuration it sees (only 4 different kinds) it will turn a continuous rotating servo either clockwise or counterclockwise.
Here's my code, any help would be greatly apreciated:
'
[noparse][[/noparse] Title ]
' What's a Microcontroller - String Aligner 1.bs2
' String Aligner 1
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Declarations ]
'
[noparse][[/noparse] Initialization ]
direction VAR Bit
'
[noparse][[/noparse] Main Routine ]
DO
· GOSUB Check_Switches
· GOSUB Turn_Servo
· GOSUB Display
LOOP
'
[noparse][[/noparse] Subroutines ]
Check_Switches:
IF (IN1=0) AND (IN2=0) THEN
direction=0
ELSEIF (IN1=0) AND (IN2=1) THEN
direction=1
ELSEIF (IN1=1) AND (IN2=1) THEN
direction=0
ELSEIF (IN1=1) AND (IN2=0) THEN
direction=1
ENDIF
RETURN
Turn_Servo:
IF direction=0 THEN
· PULSOUT 14, 1000
· PAUSE 18
ELSEIF direction=1 THEN
· PULSOUT 14, 500
· PAUSE 18
ENDIF
RETURN
Display:
IF direction=1 THEN
DEBUG HOME, "Turning right"
ELSEIF direction=0 THEN
DEBUG HOME, "Turning left "
ENDIF
RETURN
Comments
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Tech Support
dandreae@parallax.com
www.parallax.com
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
Post Edited (Jon Williams) : 1/16/2005 5:54:13 PM GMT
Check_Switches:
direction = PIN1 ^ PIN2
RETURN
I'll look up what the ^ sign means.
0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0
The way to remember is this: If one bit or the other is 1 -- but NOT both -- then the result is 1.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA