Shop OBEX P1 Docs P2 Docs Learn Events
program not looping — Parallax Forums

program not looping

navyguy0521navyguy0521 Posts: 7
edited 2021-10-16 09:04 in BASIC Stamp

Hi,

Sorry but my last posting must have been confusing.
Just trying to make this very simple program loop (repeat indefinitely)

Please tell exactly what to type at the end so this will happen.

Thank you very much.

 '{$STAMP BS2}
' {$PORT COM21}
 '($PBASIC 2.5}



HIGH 1
PAUSE 100
LOW 1
PAUSE 10000

HIGH 1
PAUSE 100
LOW 1
PAUSE 10000

HIGH 2
PAUSE 200
LOW 2
PAUSE 10000


HIGH 3
PAUSE 200
LOW 3
 HIGH 3
 HIGH 2
PAUSE 100
LOW 2
PAUSE 10000
HIGH 4
PAUSE 100
LOW 4
PAUSE 10000
HIGH 1
PAUSE 100
LOW 1
PAUSE 10000
HIGH 2
PAUSE 100
LOW 2
PAUSE 10000
 HIGH 1
PAUSE 100
LOW 1
PAUSE 10000
HIGH 2
PAUSE 100
LOW 2
PAUSE 10000
HIGH 3
PAUSE 100
LOW 3
HIGH 4
PAUSE 100
LOW 4
HIGH 1
PAUSE 100
LOW 1
PAUSE 10000

HIGH 5
PAUSE 100
LOW 5
PAUSE 500
HIGH 1
PAUSE 100
LOW 1
PAUSE 10000
HIGH 1
PAUSE 100
LOW 1
PAUSE 1000

GOTO

Comments

  •  '{$STAMP BS2}
    ' {$PORT COM21}
     '($PBASIC 2.5}
    
    DO
    
    HIGH 1
    PAUSE 100
    LOW 1
    PAUSE 10000
    
    HIGH 1
    PAUSE 100
    LOW 1
    PAUSE 10000
    
    HIGH 2
    PAUSE 200
    LOW 2
    PAUSE 10000
    
    
    HIGH 3
    PAUSE 200
    LOW 3
     HIGH 3
     HIGH 2
    PAUSE 100
    LOW 2
    PAUSE 10000
    HIGH 4
    PAUSE 100
    LOW 4
    PAUSE 10000
    HIGH 1
    PAUSE 100
    LOW 1
    PAUSE 10000
    HIGH 2
    PAUSE 100
    LOW 2
    PAUSE 10000
     HIGH 1
    PAUSE 100
    LOW 1
    PAUSE 10000
    HIGH 2
    PAUSE 100
    LOW 2
    PAUSE 10000
    HIGH 3
    PAUSE 100
    LOW 3
    HIGH 4
    PAUSE 100
    LOW 4
    HIGH 1
    PAUSE 100
    LOW 1
    PAUSE 10000
    
    HIGH 5
    PAUSE 100
    LOW 5
    PAUSE 500
    HIGH 1
    PAUSE 100
    LOW 1
    PAUSE 10000
    HIGH 1
    PAUSE 100
    LOW 1
    PAUSE 1000
    
    LOOP
    

    you should indent the lines between DO and LOOP

    Enjoy!

    Mike

  • JonnyMacJonnyMac Posts: 9,159
    edited 2021-10-16 18:47

    Sorry but my last posting must have been confusing.
    Just trying to make this very simple program loop (repeat indefinitely)

    In my first response to you I showed you how to use GOTO. It must be followed by a label. The label must exist in the program. This information is available in the help file that is linked to the BASIC Stamp editor.

    Main:
      HIGH 1
      PAUSE 100
      LOW 1
      PAUSE 10000
    
      HIGH 1
      PAUSE 100
      LOW 1
      PAUSE 10000
    
      HIGH 2
      PAUSE 200
      LOW 2
      PAUSE 10000
    
      HIGH 3
      PAUSE 200
      LOW 3
      HIGH 3
      HIGH 2
      PAUSE 100
      LOW 2
      PAUSE 10000
      HIGH 4
      PAUSE 100
      LOW 4
      PAUSE 10000
      HIGH 1
      PAUSE 100
      LOW 1
      PAUSE 10000
      HIGH 2
      PAUSE 100
      LOW 2
      PAUSE 10000
      HIGH 1
      PAUSE 100
      LOW 1
      PAUSE 10000
      HIGH 2
      PAUSE 100
      LOW 2
      PAUSE 10000
      HIGH 3
      PAUSE 100
      LOW 3
      HIGH 4
      PAUSE 100
      LOW 4
      HIGH 1
      PAUSE 100
      LOW 1
      PAUSE 10000
    
      HIGH 5
      PAUSE 100
      LOW 5
      PAUSE 500
      HIGH 1
      PAUSE 100
      LOW 1
      PAUSE 10000
      HIGH 1
      PAUSE 100
      LOW 1
      PAUSE 1000
    
      GOTO Main
    

    Since you're new, let me give you another tip that will help you long term: As easy as it is to use the pin number directly, don't do this. Spend a few minutes naming the pins appropriate for the function they perform. This has two benefits: 1) The code is easier to read and maintain, and 2) If you have to re-wire your circuit, changing the PIN definition in one place makes things significantly cleaner.

    As Mike pointed out, DO..LOOP is another structure that can be used for looping. For long stretches of code like yours, though, I think GOTO Label is better suited. Use DO..LOOP for small segments of code.

  • Thank you guys. Really appreciate it..

  • Here is another spin on it using the Gosub, I cut out the lenghty pauses and added a Debug so you can see it looping

Sign In or Register to comment.