converting BS2 code to BS1
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
·
'----- [noparse][[/noparse] Title ] ------------------------------------------------------ ' ' What's a Microcontroller - String Aligner 1.BS1 ' String Aligner 1 ' ' {$STAMP BS1} ' {$PBASIC 1.0} '----- [noparse][[/noparse] Declarations ] ----------------------------------------------- '----- [noparse][[/noparse] Initialization ] --------------------------------------------- SYMBOL direction = BIT0 '----- [noparse][[/noparse] Main Routine ] ----------------------------------------------- Main: GOSUB Check_Switches GOSUB Turn_Servo GOSUB Display GOTO Main '----- [noparse][[/noparse] Subroutines ] ------------------------------------------------ Check_Switches: direction = PIN1 ^ PIN2 RETURN Turn_Servo: IF direction = 1 THEN Turn_1 PULSOUT 7, 200 GOTO Turn_Exit Turn_1: PULSOUT 7, 50 Turn_Exit: PAUSE 18 RETURN Display: DEBUG CLS IF direction = 1 THEN Display_1 DEBUG "Turning left" GOTO Display_Exit Display_1: DEBUG "Turning right" Display_Exit: RETURN▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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