Shop OBEX P1 Docs P2 Docs Learn Events
Code errors — Parallax Forums

Code errors

Sing AmericaSing America Posts: 17
edited 2005-12-04 07:08 in Learn with BlocklyProp
Hi All,
I have been working on vaccuum program in class with students and after 3 weeks of classes we are stuck with the code.
Currently it works for the first part of the spiral then skips through the rest.· I tried to add wait time thinking the switches needed to reset themselves and it through the entire process off.· I have used the debug window to test the switches and during the zigzag section it looks at the first switch and then travels to the end of the program kind of quickly.· I am sure it is one little thing but we can not pull it off.· Any help would be appreciated.
Thanks Mark Devine
Sorry I could not attach it so it is in its long form.

' {$STAMP BS2}
' {$PBASIC 2.5}
Counter VAR Word
frequency VAR Word
duration VAR Word
DEBUG "Turn On...", CR
PAUSE 100
· FOR Duration = 15 TO 1 STEP 1
··· FOR Frequency = 2000 TO 2500 STEP 20
····· FREQOUT 9, Duration, Frequency
··· NEXT
IF (IN6 = 1) THEN zigzag
IF (IN7 = 1) THEN zigzag
IF (IN8 = 1) THEN zigzag
GOSUB Spiral

'Subroutines
··· Spiral:
DEBUG "spiral", CR
FOR Counter = 1 TO 245
PULSOUT 12, 751
PULSOUT 13, 400
PAUSE 20
IF (IN6 = 1) THEN zigzag
IF (IN7 = 1) THEN zigzag
IF (IN8 = 1) THEN zigzag
NEXT
FOR Counter = 1 TO 350
PULSOUT 12, 760
PULSOUT 13, 400
PAUSE 20
IF (IN6 = 1) THEN zigzag
IF (IN7 = 1) THEN zigzag
IF (IN8 = 1) THEN zigzag
NEXT
FOR counter = 1 TO 450
PULSOUT 12, 770
PULSOUT 13, 400
PAUSE 20
IF (IN6 = 1) THEN zigzag
IF (IN7 = 1) THEN zigzag
IF (IN8 = 1) THEN zigzag
NEXT
FOR counter = 1 TO 590
PULSOUT 12, 790
PULSOUT 13, 400
PAUSE 20
IF (IN6 = 1) THEN zigzag
IF (IN7 = 1) THEN zigzag
IF (IN8 = 1) THEN zigzag
NEXT
FOR counter = 1 TO 800
PULSOUT 12, 815
PULSOUT 13, 400
PAUSE 20
IF (IN6 = 1) THEN zigzag
IF (IN7 = 1) THEN zigzag
IF (IN8 = 1) THEN zigzag
NEXT
FOR counter = 1 TO 1000
PULSOUT 12, 850
PULSOUT 13, 400
PAUSE 20
IF (IN6 = 1) THEN zigzag
IF (IN7 = 1) THEN zigzag
IF (IN8 = 1) THEN zigzag
NEXT
GOSUB spiral
ZigZag:
DEBUG "Zig_Zag", CR
FOR counter = 1 TO 200
PULSOUT 12, 850
PULSOUT 13, 650
PAUSE 20
IF (IN6 = 1) THEN rover
DEBUG "1", CR
IF (IN7 = 1) THEN rover
DEBUG "2", CR
IF (IN8 = 1) THEN rover
DEBUG "3", CR
NEXT
FOR counter = 1 TO 80
PULSOUT 12, 650
PULSOUT 13, 650
PAUSE 20
IF (IN6 = 1) THEN rover
IF (IN7 = 1) THEN rover
IF (IN8 = 1) THEN rover
NEXT
FOR counter = 1 TO 200
PULSOUT 12, 850
PULSOUT 13, 650
PAUSE 20
IF (IN6 = 1) THEN rover
IF (IN7 = 1) THEN rover
IF (IN8 = 1) THEN rover
NEXT
FOR counter = 1 TO 80
PULSOUT 12, 850
PULSOUT 13, 850
PAUSE 20
IF (IN6 = 1) THEN rover
IF (IN7 = 1) THEN rover
IF (IN8 = 1) THEN rover
NEXT
GOTO zigzag
rover:
DEBUG "rover", CR
DO
GOSUB Forward2
GOSUB Turn_Right
LOOP
Forward2:
DEBUG "forward2", CR
DO
PULSOUT 12, 850
PULSOUT 13, 650
PAUSE 20
IF (IN6 = 1) THEN Turn_Right
IF (IN7 = 1) THEN Turn_Right
IF (IN8 = 1) THEN Turn_Right
LOOP
Turn_Right:
DEBUG "turn right", CR
FOR counter = 1 TO 80
PULSOUT 12, 850
PULSOUT 13, 850
PAUSE 20
IF (IN6 = 1) THEN rover
IF (IN7 = 1) THEN rover
IF (IN8 = 1) THEN rover
NEXT
GOSUB rover
RETURN

Comments

  • japerjaper Posts: 105
    edited 2005-11-28 10:30
    hello Sing America

    i noiticed 2 things
    the main rountine is not listed
    and you do not have return after each subroutine

    japer
  • carbonAgentcarbonAgent Posts: 4
    edited 2005-12-04 07:02
    Hello Mark,

    One suggestion I would make to you is add some formatting. Many errors will become more obvious with formatting. Keep GOTO's to a very minimum. They make it difficult to follow the code. Also you should end all subroutines with a RETURN. Without analyzing the code very much I noticed a couple of things...

    1) your first FOR is missing a NEXT
    2) your spiral subroutine keeps calling itself with GOSUB (all your subroutines should end with a RETURN)
    3) Your rover subroutine is an infinite loop
    4) Turn_right calls Rover and then Rover calls Forward2 and then Forward2 calls Rover again (the second call in Rover will never be reached)
    5) the last will return will never be reached

    - you might be busy for a while - have fun!

    p.s. I formatted your code a little...

    '{$STAMP BS2}
    '{$PBASIC 2.5}

    Counter VAR Word
    frequency VAR Word
    duration VAR Word

    DEBUG "Turn On...", CR
    PAUSE 100

    FOR Duration = 15 TO 1 STEP 1
    FOR Frequency = 2000 TO 2500 STEP 20
    FREQOUT 9, Duration, Frequency
    NEXT

    IF (IN6 = 1) THEN zigzag
    IF (IN7 = 1) THEN zigzag
    IF (IN8 = 1) THEN zigzag

    GOSUB Spiral

    '
    'Subroutines
    '
    Spiral:

    DEBUG "spiral", CR

    FOR Counter = 1 TO 245
    PULSOUT 12, 751
    PULSOUT 13, 400
    PAUSE 20
    IF (IN6 = 1) THEN zigzag
    IF (IN7 = 1) THEN zigzag
    IF (IN8 = 1) THEN zigzag
    NEXT

    FOR Counter = 1 TO 350
    PULSOUT 12, 760
    PULSOUT 13, 400
    PAUSE 20
    IF (IN6 = 1) THEN zigzag
    IF (IN7 = 1) THEN zigzag
    IF (IN8 = 1) THEN zigzag
    NEXT

    FOR counter = 1 TO 450
    PULSOUT 12, 770
    PULSOUT 13, 400
    PAUSE 20
    IF (IN6 = 1) THEN zigzag
    IF (IN7 = 1) THEN zigzag
    IF (IN8 = 1) THEN zigzag
    NEXT

    FOR counter = 1 TO 590
    PULSOUT 12, 790
    PULSOUT 13, 400
    PAUSE 20
    IF (IN6 = 1) THEN zigzag
    IF (IN7 = 1) THEN zigzag
    IF (IN8 = 1) THEN zigzag
    NEXT

    FOR counter = 1 TO 800
    PULSOUT 12, 815
    PULSOUT 13, 400
    PAUSE 20
    IF (IN6 = 1) THEN zigzag
    IF (IN7 = 1) THEN zigzag
    IF (IN8 = 1) THEN zigzag
    NEXT

    FOR counter = 1 TO 1000
    PULSOUT 12, 850
    PULSOUT 13, 400
    PAUSE 20
    IF (IN6 = 1) THEN zigzag
    IF (IN7 = 1) THEN zigzag
    IF (IN8 = 1) THEN zigzag
    NEXT

    GOSUB spiral

    '
    ZigZag:

    DEBUG "Zig_Zag", CR

    FOR counter = 1 TO 200
    PULSOUT 12, 850
    PULSOUT 13, 650
    PAUSE 20
    IF (IN6 = 1) THEN rover
    DEBUG "1", CR
    IF (IN7 = 1) THEN rover
    DEBUG "2", CR
    IF (IN8 = 1) THEN rover
    DEBUG "3", CR
    NEXT

    FOR counter = 1 TO 80
    PULSOUT 12, 650
    PULSOUT 13, 650
    PAUSE 20
    IF (IN6 = 1) THEN rover
    IF (IN7 = 1) THEN rover
    IF (IN8 = 1) THEN rover
    NEXT

    FOR counter = 1 TO 200
    PULSOUT 12, 850
    PULSOUT 13, 650
    PAUSE 20
    IF (IN6 = 1) THEN rover
    IF (IN7 = 1) THEN rover
    IF (IN8 = 1) THEN rover
    NEXT

    FOR counter = 1 TO 80
    PULSOUT 12, 850
    PULSOUT 13, 850
    PAUSE 20
    IF (IN6 = 1) THEN rover
    IF (IN7 = 1) THEN rover
    IF (IN8 = 1) THEN rover
    NEXT

    GOTO zigzag

    '
    rover:

    DEBUG "rover", CR

    DO
    GOSUB Forward2
    GOSUB Turn_Right
    LOOP

    '
    Forward2:

    DEBUG "forward2", CR

    DO
    PULSOUT 12, 850
    PULSOUT 13, 650
    PAUSE 20
    IF (IN6 = 1) THEN Turn_Right
    IF (IN7 = 1) THEN Turn_Right
    IF (IN8 = 1) THEN Turn_Right
    LOOP

    '
    Turn_Right:

    DEBUG "turn right", CR

    FOR counter = 1 TO 80
    PULSOUT 12, 850
    PULSOUT 13, 850
    PAUSE 20
    IF (IN6 = 1) THEN rover
    IF (IN7 = 1) THEN rover
    IF (IN8 = 1) THEN rover
    NEXT

    GOSUB rover
    RETURN
  • carbonAgentcarbonAgent Posts: 4
    edited 2005-12-04 07:08
    oops - that didn't work out too well.

    Formatted code attched. (I think tongue.gif)
Sign In or Register to comment.