Shop OBEX P1 Docs P2 Docs Learn Events
Multiple commands at the same time — Parallax Forums

Multiple commands at the same time

edited 2014-04-22 23:32 in BASIC Stamp
So I'm new to the PBasic editor. I was wondering if I could run multiple programs or commands at the same time on the stamp. For example: In my class we have to make an LED light show and music is optional. What I would like to do is have a song playing during the light show. Here's an example of what I would like:

GOTO song [Also] GOTO lights

song:
freqout pin, duration, frequency
code
code
etc.
GOTO song

lights:
HIGH 1
PAUSE 250
LOW 1
HIGH 2
HIGH 3
PAUSE 1000
Etc.
GOTO lights

This is just an idea of what I want. Is it even possible to have multiple commands going at once? If there is, I would appreciate it if you would tell me the correct syntax. Thanks in advance.

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-04-22 10:46
    What you want to do is switch back and forth between tasks quickly so it appears they're happening at the same time. Turn a LED on, play a note, change the LED, play another note, etc. The LEDs will stay on or off so the program can do other things while the LED is on. However the notes don't hold. The BS2 has to wait for the note to finish before it will continue. So you want to make any LED changes between notes.
  • 72sonett72sonett Posts: 82
    edited 2014-04-22 11:53
    .... I was wondering if I could run multiple programs or commands at the same time on the stamp.
    You can run multiple programs (in multiple ´slots´) but not at the same time. The BS s a sequential computer, it can only do one thing at a time, step by step.

    However, sometimes you can make it seem like it is doing multiple things at a time by multiplexing, that is doing several things after each other repeatedly and doing them fast enough so it seems they happen at the same time.
  • GenetixGenetix Posts: 1,752
    edited 2014-04-22 23:32
    The BS2 can only run one command at a time.
    Instead of PAUSE 250 you could play a short tone. You can play a long tone instead of PAUSE 1000 or play several.

    Do you have a copy of the BASIC Stamp Reference Manual or What's a Microcontroller?
    Chapter 8 of What's a Microcontroller is on sounds and music.

    Look up the RANDOM command.

    You can find BS2 command online here:
    http://www.parallax.com/go/PBASICHelp/
Sign In or Register to comment.