Shop OBEX P1 Docs P2 Docs Learn Events
Running multiple loops at once — Parallax Forums

Running multiple loops at once

surfline27surfline27 Posts: 8
edited 2011-09-29 17:58 in BASIC Stamp
Hi

I'm new at Basic Stamp (and programming in general) and I was wondering if there is a way to run simple multiple loops at the same time.

EDIT: I'm using this code with the BoeBot Robot Kit, so what I'm trying to do is have blinking lights, beeping and movement at the same time

Like for example if I want all three loops below to run simultaneously, how can I do it?

DO
HIGH 13
HIGH 12
PAUSE 500
LOW 13
LOW 12
PAUSE 500
LOOP

DO
FREQOUT 4, 500, 5000
LOOP

DO
PULSOUT 13, 810
PULSOUT 12, 720
LOOP
Any help would be greatly appreciated.

Thanks

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-09-29 14:14
    The problem with the three loops you're showing is that some contain statements that pause or stop execution for some amount of time. If you combine these three pieces of code they will not work together as they are.

    What you want to do can be done, but for the LED blinking you cannot use PAUSE statements and the FREQOUT command would need to be a shorter duration, which will also cause it to sound like it is beeping in short bursts. For the LEDs you would use a passive loop with a counter and this would also require some empirical testing to get the right value.
  • ercoerco Posts: 20,256
    edited 2011-09-29 15:17
    Per Chris, your program has to everything at once. Start with the servo loop:

    FOR W1=1 to 500
    PULSOUT 13, 810
    PULSOUT 12, 720
    PAUSE 20
    NEXT

    Get that doing what you want, then slowly work in toggling LEDs and getting some sound bursts out. Everything must be woven together around the 50 hz pulse trains required to keep your servos happy.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-29 16:04
    The Stamps are single threaded processors. They can only do one thing at a time. You can interleave different things so it all looks like it's happening at the same time, but it's not really.
  • surfline27surfline27 Posts: 8
    edited 2011-09-29 17:58
    Ok thanks for all your help. I've never done anything like this before so I was just wondering.
Sign In or Register to comment.