Shop OBEX P1 Docs P2 Docs Learn Events
Subroutine problem — Parallax Forums

Subroutine problem

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

Comments

  • Hal AlbachHal Albach Posts: 747
    edited 2017-02-18 20:55
    DO
    PAUSE 200
    GOTO photo_1          ' Have you tried GOSUB instead of GOTO?
    PAUSE 100
    GOTO photo_2          ' And here too!
    LOOP
    

    Page 375 of the Manual states a RETURN without a GOSUB causes the program to return to the top.
  • You are absolutely right Hal. I replaced the command GOTO with GOSUB, also I eliminated the Home command for photo_2 in DEBUG statement so that the statement for photo_2 will appear under photo_1 statement. Thanks
Sign In or Register to comment.