sound modulated LED light show with BS2
For a while, I have been wanting to have something like a LED color organ (flashes lights to the beat of the music). I didn't have the time or parts to build an analog version (it used five op amps and a boatload of resistors and capacitors), so I built one using a BS2. I first took the left speaker from my computer and took it apart. I connected the black lead (GND) to the ground pole of the PDB that I was using and connected the red lead (Aduio signal) to the input of the aduio amplifier on the PDB. I took the positive output from the aduio amplifier to Pin 0 on my Basic Stamp (connecting it through a 2K resistor for protection). I then loaded the code below (after connecting the LEDs) and turned the volume on the PDB's aduio amplifier to it's maximum value. Next, I turned up the volume on the speaker's built in amplifier to about 3/5 of the way up. I then played some test music and I saw a few flashing LEDs!! success!!!!!
Code:
' {$STAMP BS2}
' {$PBASIC 2.5}
rndVal VAR Word ' random number
dieVal VAR Nib ' new die value
doSpin VAR Nib ' spinner update control
t VAR Word
DO
PAUSE 10
DEBUG DEC IN0, CR
RANDOM rndVal ' stir random value
dieVal = (rndVal // 4) + 1 ' get die val, 1 - 6
doSpin = (doSpin + 1) // 10 ' update spin timer
IF IN0 = 0 THEN
HIGH dieval
PAUSE 50
ELSE
LOW dieval
PAUSE 50
ENDIF
LOOP
Code:
' {$STAMP BS2}
' {$PBASIC 2.5}
rndVal VAR Word ' random number
dieVal VAR Nib ' new die value
doSpin VAR Nib ' spinner update control
t VAR Word
DO
PAUSE 10
DEBUG DEC IN0, CR
RANDOM rndVal ' stir random value
dieVal = (rndVal // 4) + 1 ' get die val, 1 - 6
doSpin = (doSpin + 1) // 10 ' update spin timer
IF IN0 = 0 THEN
HIGH dieval
PAUSE 50
ELSE
LOW dieval
PAUSE 50
ENDIF
LOOP