Building a silent metronome.....need help with some stuff
I'm trying to build a silent metronome by using a dip switch and multiple outputs from the pins, and the dip switch to be all tied to the output of an LED with a 470 ohm resistor for current limiting. I currently have the times required for 6 different BPM (beats per minute) and have tested them individually using a DO LOOP statement. The complication is trying to fire all of the pins at the same time and not have complications with the PAUSE commands of the previous set messing up the timing of the second and subsequent pin firings. This code is what I have so far.....any suggestions on how to get them all to fire at once, but keep the right timings? I'll attach the BS2 file for those who wanna mess with it
' Silent Metronome
' Using an LED and a DIP switch, you can simulate many different BPM (Beats Per Minute) for use in music.
' {$STAMP BS2}
' {$PBASIC 2.5}
' run pins 8 through 13, bpm 69 through 160
DO
HIGH 8
PAUSE 20
LOW 8
PAUSE 840 ' these pause times create 69 bpm
LOOP
DO
HIGH 9
PAUSE 20
LOW 9
PAUSE 720 ' these pause times create 80 bpm
LOOP
DO
HIGH 10
PAUSE 20
LOW 10
PAUSE 570 ' these pause times create 100 bpm
LOOP
DO
HIGH 11
PAUSE 20
LOW 11
PAUSE 465 ' these pause times create 120 bpm
LOOP
DO
HIGH 12
PAUSE 20
LOW 12
PAUSE 385 ' these pause times create 144 bpm
LOOP
DO
HIGH 13
PAUSE 20
LOW 13
PAUSE 340 ' these pause times create 160 bpm
LOOP
bs2
800B

Comments
Please clarify for help. BTW, a rotary selector switch, such as http://www.radioshack.com/product/index.jsp?productId=2062536 might be more intuitive than a dip switch.
It's meant to use different pins for each high low (going from pin 8 for the lowest to 13 for the highest), and the DIP switch would select which one to go. Just using a DIP switch because that's what I had available for cheap. What I meant by "firing all the pins at once" was just wanting to have each "high low" selection go all at once, so I could then choose which BPM I wanted to output to the LED using the switch.
I'll go up and edit the code to change what it's saying.
WAM, of course: http://www.parallax.com/Portals/0/Downloads/docs/prod/edu/28123-WAM-v3.0.pdf
Per my last post, you'll just use the DIP switch as an input device to tell the Stamp which timing routine to use. It can only do one thing at a time. Read that book and work through it, focusing on inputs and outputs.
' Silent Metronome ' Using an LED and a DIP switch, you can simulate many different BPM (Beats Per Minute) for use in music. ' {$STAMP BS2} ' {$PBASIC 2.5} ' run pin 8, bpm 69 through 160 DO IF (value = 0), THEN GOSUB bpm_69 timeCounter = timeCounter + 1 IF (value = 1), THEN GOSUB bpm_80 timeCounter = timeCounter + 1 IF (value = 2), THEN GOSUB bpm_100 timeCounter = timeCounter + 1 IF (value = 3), THEN GOSUB bpm_120 timeCounter = timeCounter + 1 IF (value = 4), THEN GOSUB bpm_144 timeCounter = timeCounter + 1 IF (value = 5), THEN GOSUB bpm_160 LOOP bpm_69: DO HIGH 8 PAUSE 20 LOW 8 PAUSE 840 ' these pause times create 69 bpm LOOP bpm_80: DO HIGH 8 PAUSE 20 LOW 8 PAUSE 720 ' these pause times create 80 bpm LOOP bpm_100: DO HIGH 8 PAUSE 20 LOW 8 PAUSE 570 ' these pause times create 100 bpm LOOP bpm_120: DO HIGH 8 PAUSE 20 LOW 8 PAUSE 465 ' these pause times create 120 bpm LOOP bpm_144: DO HIGH 8 PAUSE 20 LOW 8 PAUSE 385 ' these pause times create 144 bpm LOOP bpm_160: DO HIGH 8 PAUSE 20 LOW 8 PAUSE 340 ' these pause times create 160 bpm LOOPA quick way to do this would be to read the dip switches and derive a PAUSE based on that.
Sort of like what you've alluded to above.
Then you'd enter your DO...LOOP where you'd flash your LED and then PAUSE, based on
that initial dip switch reading.
The PAUSEs you'll have to sort of work out by trial and error (as
one beat = one flash time + the PAUSE time + the instruction execution time
to do that.)
You'd be "trapped" in an endless DO...LOOP, but you'd get out of it by pushing
the Reset button.
If you had a long PAUSE at the beginning, it'd give you time to set switches
before the Stamp reads them.
To change BPMs on-the-fly would involve a more complex approach, re-reading
the DIPs while not losing time in the process.
Does that make sense?