Subroutine problem
bluejay
Posts: 131
in BASIC Stamp
Could someone please explain why photo_2 will not execute when photocell7 is running? The problem is that photo_1 runs fine, however photo_2 is never executed. I could however run either/or but not both at the same time. Enclosed is the program. Thanks.
' {$STAMP BS2}
' {$PBASIC 2.5}
'photocell7
'photocell1 one side to 253o ohms resistor other side to pins 18,17 of 2803A.
'photocell2 one side to 1k resistor other side to pins 16,15 of 2803A.
'1k resistor pullup on pins 18,17 of IC.
'1k resistor pullup on pins 16,15 of IC.
photo1 VAR Byte
photo2 VAR Byte
DO
PAUSE 200
GOTO photo_1
PAUSE 100
GOTO photo_2
LOOP
photo_1:
HIGH 15
RCTIME 15, 1, photo1
IF photo1=0 THEN
DEBUG HOME,"photo_1 = OFF " ,CR
ELSE
DEBUG HOME,"photo_1 = ON ",CR
ENDIF
RETURN
photo_2:
HIGH 14
RCTIME 14, 1, photo2
IF photo2=0 THEN
DEBUG HOME,"photo_2 = OFF ",CR
ELSE
DEBUG HOME,"photo_2 = ON ",CR
ENDIF
RETURN
' {$STAMP BS2}
' {$PBASIC 2.5}
'photocell7
'photocell1 one side to 253o ohms resistor other side to pins 18,17 of 2803A.
'photocell2 one side to 1k resistor other side to pins 16,15 of 2803A.
'1k resistor pullup on pins 18,17 of IC.
'1k resistor pullup on pins 16,15 of IC.
photo1 VAR Byte
photo2 VAR Byte
DO
PAUSE 200
GOTO photo_1
PAUSE 100
GOTO photo_2
LOOP
photo_1:
HIGH 15
RCTIME 15, 1, photo1
IF photo1=0 THEN
DEBUG HOME,"photo_1 = OFF " ,CR
ELSE
DEBUG HOME,"photo_1 = ON ",CR
ENDIF
RETURN
photo_2:
HIGH 14
RCTIME 14, 1, photo2
IF photo2=0 THEN
DEBUG HOME,"photo_2 = OFF ",CR
ELSE
DEBUG HOME,"photo_2 = ON ",CR
ENDIF
RETURN
Comments
Page 375 of the Manual states a RETURN without a GOSUB causes the program to return to the top.