Multiple DO.......LOOP running at once
nrsmac
Posts: 42
Hi, I'm not great at programming with the bs2, So I was wondering. Do you know a way ro run multiple DO......LOOP commands at once? That would be great. Thanks!
nrsmac
nrsmac
Comments
'
You have some tunes playing,Stamp editor open,Debug window open,and the Parallax forums open.This all seems to be running at the same time in parallel,But it's not.
'
If you write clever code with the BS2 you can get similar results.
'
This is where some good reading comes into play.
'
http://www.parallax.com/Portals/0/Downloads/docs/books/sw/Web-SW-v2.1.pdf
http://www.parallax.com/Portals/0/Downloads/docs/prod/stamps/web-BSM-v2.2.pdf
When I nest the blinking LED loop in with the FREQOUT command loop, no more code can run while the nested loop is running. The LEDs wil blink, but no sound will play.
'
Did you get the BS2/code working?
'
"Cheer up o' chap"....(Lame USA attempt to cheer up a Britt (UK))...sorry
'
There are other ways to reach the same goal. Often using different commands.
'
Ditch the Impossible out look...Think positive
'
Post Your code and we'll see what we can do with it.
' {$STAMP BS2}
' {$PBASIC 2.5}
' Deck the halls with boughs of holly
Notes DATA "C", "b", "A", "G", "F", "G", "A", "F",
' Fa la la la la la la la la
"G", "A", "b", "G", "A", "G", "F", "E", "F",
' Tis the season to be jolly
"C", "b", "A", "G", "F", "G", "A", "F",
' Fa la la la la la la la la
"G", "A", "b", "G", "A", "G", "F", "E", "F",
' Don we now out gay apparel
"G", "A", "b", "G", "A", "b", "C", "G",
' Fa la la la la la la la la
"A", "B", "C", "D", "E", "F", "E", "D", "C",
' Toll the ancient yuletide carol
"C", "b", "A", "G", "F", "G", "A", "F",
' Fa la la la la la la la la
"D", "D", "D", "D", "C", "b", "A", "G", "F", "Q"
Octaves DATA 7, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6,
7, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 7, 6,
6, 6, 7, 7, 7, 7, 7, 7, 7,
7, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 6, 6, 6, 6
Durations DATA 4, 8, 4, 4, 4, 4, 4, 4,
8, 8, 8, 8, 4, 8, 4, 4, 2,
4, 8, 4, 4, 4, 4, 4, 4,
8, 8, 8, 8, 4, 8, 4, 4, 2,
4, 8, 4, 4, 4, 8, 4, 4,
8, 8, 4, 8, 8, 4, 4, 4, 2,
4, 8, 4, 4, 4, 4, 4, 4,
8, 8, 8, 8, 4, 8, 4, 4, 2
Dots DATA 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0,
1, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0
index VAR BYTE
offset VAR NIB
noteLetter VAR BYTE
noteFreq VAR WORD
noteDuration VAR WORD
noteOctave VAR NIB
noteDot VAR BIT
DO UNTIL noteLetter = "Q"
READ Notes + index, noteLetter
LOOKDOWN noteLetter, [ "C", "d", "D", "e", "E",
"F", "g", "G", "a", "A",
"b", "B", "R", "Q" ], offset
LOOKUP offset, [ 4186, 4435, 4699, 4978, 5274,
5588, 5920, 6272, 6645, 7040,
7459, 7902, 0, 0 ], noteFreq
READ Octaves + index, noteOctave
noteOctave = 8 - noteOctave
noteFreq = noteFreq / (DCD noteOctave)
READ Durations + index, noteDuration
noteDuration = 1000 / noteDuration
READ Dots + index, noteDot
IF noteDot = 1 THEN noteDuration = noteDuration * 3 / 2
FREQOUT 8, noteDuration, noteFreq
index = index + 1
LOOP
END
and this is what i am trying to put in the code during the long FREQOUT
DO
HIGH 2
PAUSE 500
LOW 2
HIGH 3
PAUSE 500
LOW 3
HIGH 4
PAUSE 500
LOW 4
LOOP
Thanks $WMc%!
nrsmac
By the way, you said you are not great at programming with the bs2, but my compliments on a very well organized program.
http://www.youtube.com/watch?v=hYn3-6PPeZo
( I do not know how to make a hyperlink on this form )
I will try all of these suggestions. Thanks!
Why not just use the TOGGLE command?
Keep a variable with the current pin-number
Pseudo-code to insert before or after the FREQOUT:
TOGGLE LED-Pin
INC LED-Pin
IF LED-PIN = 5 THEN LED-PIN == 2
TOGGLE LED-Pin
Something like that, at least...
(Years since I coded for a BS2... )