Shop OBEX P1 Docs P2 Docs Learn Events
BS1 version of Do...Loop...? — Parallax Forums

BS1 version of Do...Loop...?

ppillardppillard Posts: 22
edited 2014-07-21 19:24 in BASIC Stamp
Hello All! I'm a relative noob, here, so please load up on your patience before you proceed. :)

So I built a simple remote start relay system for my old truck. I developed it on my trusty BS2 Homework Board, using a Parallax key fob remote. Once I had the code working with some simple LED's to indicate the vehicle was trying to start and I could lock/unlock the doors, I settled in and ordered my relays and such. To minimize power requirements, I opted for a BS1 module. This is the first time I have played with a BS1 at all.

Imagine my disappointment when the BS1 module and development board arrived and I tried to upload my code to it, only to find that the BS1 doesn't support a Do...Loop?!

Surely the BS1 has a version of Do...Loop?

Comments

  • ppillardppillard Posts: 22
    edited 2014-07-08 18:18
    Looking at the help documentation. Do I really have to create a FOR...NEXT function that constantly increments and decrements to create a pseudo LOOP function?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2014-07-08 19:19
    ppillard wrote: »
    Looking at the help documentation. Do I really have to create a FOR...NEXT function that constantly increments and decrements to create a pseudo LOOP function?

    "a pseudo LOOP"?.
    You could branch to a subroutine based on the status of a flag.
  • davejamesdavejames Posts: 4,047
    edited 2014-07-08 19:34
    ppillard,

    How are you using the DO..LOOP? If it's for nothing more than to create a continuously executing section of code, why not use a GOTO..LABEL?

    People frown using the GOTO statement in general, but sometimes "ya gotta do what ya gotta do".
  • ppillardppillard Posts: 22
    edited 2014-07-09 04:18
    Basically, my DO....LOOP just constantly listens to detect a change in button states, then has the appropriate IF...THEN to know how to react. Is there a better way to do this with the BS1? Reading the GOTO documentation, it looks like it would work fine. Why is this frowned on?
  • Mike GreenMike Green Posts: 23,101
    edited 2014-07-09 05:43
    The BUTTON statement does a lot of the processing for debouncing (and repeating) button presses and also works as a GOTO depending on the state of the button. Have a look at the description in the Stamp Manual.

    GOTOs are "frowned upon" because it's much easier to write sloppy and hard to understand code using GOTOs than DO / LOOP and other "structured control statements". Pretty much any introductory programming textbook will discuss this.
  • ppillardppillard Posts: 22
    edited 2014-07-09 05:56
    Thanks, Mike! Exactly what I was looking for. :)
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2014-07-09 06:37
    GOTO is frowned upon in C, but not in BASIC.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-07-09 14:06
    GOTO is frowned upon in C
    Why? And is it still used? My thoughts are simple. If it works for what you are trying to accomplish, then use it.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-07-09 15:24
    As there is no DO...LOOP support in PBASIC V1.0 you must use a GOTO construct such as:
    Main:
      <your code here>
      GOTO Main
    
  • ercoerco Posts: 20,256
    edited 2014-07-09 16:16
    Not having DO loops isn't the end of the world. Here's a tiny snippet to monitor at a single switch on pin 0:

    a:if PIN0=0 then a ' wait until pin 0 goes high

    which loops eternally until Pin 0 goes high. A chicken in every pot, a workaround for every situation. The BS-1 is twenty years old, after all, but still plenty useful for many apps.
  • ercoerco Posts: 20,256
    edited 2014-07-09 16:31
    In the extreme case, here's a program which is nothing but GOTO commands, a fairly useless program, other than making an interesting animation in the simulator and upsetting the purists.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2014-07-09 19:39
    NWCCTV wrote: »
    Why? And is it still used? My thoughts are simple. If it works for what you are trying to accomplish, then use it.

    GOTO is totally BASIC. C64 BASIC had it - and GOSUB.

    In C it's seen as an embarrassment, a vestigial carry-over, but it's still available.
    You'll have to haunt some C sites.
    Proper object-oriented programming should do without. If you can't manage, someone will show you how (if you ask the right way.)

    GOTO is indispensable to the BS1 (BASIC) paradigm.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-07-10 08:28
    erco, what is that a simulator for (what platform)?
  • ercoerco Posts: 20,256
    edited 2014-07-10 15:41
    erco, what is that a simulator for (what platform)?

    Picaxe. Busted! :)
  • GenetixGenetix Posts: 1,749
    edited 2014-07-10 18:57
    Prior to PBASIC 2.5 the only way to do a loop was by doing this
    Label:
    <Statement(s)>
    GOTO Label
    

    Older texts such as Industrial Control had code in this form as well as older versions of other Stamps-in-class texts. Too bad these aren't on the Parallax website anymore because they are great for reference.


    On another note, Assembly Language makes extensive use of the Jump instruction which is similar to GOTO in BASIC. BASIC uses what is called Direct addressing where the program jumps directly to the new location. Assembly also has indexed and indirect addressing and some chips even have an Index register that used for accessing memory.
    Look at Propeller Assembly code and you will JMP (Jump) used quite frequently.
  • trookstrooks Posts: 228
    edited 2014-07-20 20:32
    erco wrote: »
    .... The BS-1 is twenty years old, after all, but still plenty useful for many apps.

    OUCH! Please let us not disparage old.

    My goose gun is older than I am but it still puts what I aim at on the table. My Pfluger reel is just as old and it still puts snapper and grouper on the table.


    The reason I am using BS2s is that I needed more I/O pins and faster speed for my current project.

    As for humans... getting old ain't for sissies.


    Tim
    (As old as my hair and slightly older than my teeth.)
  • ppillardppillard Posts: 22
    edited 2014-07-21 11:13
    As a noob, I risk showing a fair amount of ignorance. Nonetheless, I have to say that the BS1 is exactly what this project (a simple remote start and door lock/unlock routine) needed. I chose it because it had the exact number of IO pins I needed (8), and for its miniscule consumption of power. I didn't need speed, or multi-tasking or a lot of fluff. I just needed a simple processor for a simple device. Works perfect.

    Thanks for the good data, guys! She's up and running. :)
  • ercoerco Posts: 20,256
    edited 2014-07-21 19:24
    Bravo, ppillard! Glad to hear you're another satisfied Parallax customer. As you've seen, there's no shortage of helpful replies here. Hope you stick around for more fun.

    BTW, the BS1 is still perfect for many projects. Just enough power & pins, and well-documented simplicity. That BS1-IC is tiny and tucks in anywhere. I wish I would have stockpiled (OK, hoarded) more BS1 project boards back when they were $14.99. Twice that now!

    http://www.parallax.com/product/27112
Sign In or Register to comment.