Shop OBEX P1 Docs P2 Docs Learn Events
Totally dumb to this. — Parallax Forums

Totally dumb to this.

lousyshotlousyshot Posts: 11
edited 2012-09-09 02:35 in BASIC Stamp
Programming is a foreign language to me.
Entered a simple loop program. How do you stop it without substatuting another program?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-09-08 21:23
    Start with the "What's a Microcontroller?" tutorial. You should have the "Basic Stamp Syntax and Reference Manual" as well.

    A microcontroller will do what you tell it to do. If you have a program with a simple loop ... it will loop as long as the chip has power just like you told it to do. If you substitute another program (by downloading a new one to the chip), it will start to do that instead. If you want the loop to stop, you have to provide some statement that will cause the loop to stop so that the program can continue on to something else. Look at the DO / LOOP statement, particularly with a WHILE or UNTIL clause. You could also use a FOR / NEXT loop to loop some specified number of times. You could include an IF / THEN statement somewhere in your simple loop with a GOTO to somewhere else in your program.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-09-09 02:35
    The short answer is that sometimes all you want is a mircocontroller to perform an infinite loop where a sequence of events occurs predictably and accurately -- like blinking a series of lights or making a sound.

    If you what to get out of a loop - you have a few options - Count how many times you want to loop and then jump out; or test some condition and when it occurs or doesn't occur, jump out of the loop.

    This is NOT rocket science and PBasic is rather easy.

    One choice of jumping out ouf a loop is to save power when you no longer need the loop. That is what the END command in PBasic is for, but just putting an END inside a loop destroys the loop. You need to either count or test your loop and after you jump out you can use the END command.

    If you want to start again, you hit the RESET button and the cycle begins anew.
Sign In or Register to comment.