Shop OBEX P1 Docs P2 Docs Learn Events
sound modulated LED light show with BS2 — Parallax Forums

sound modulated LED light show with BS2

bomberbomber Posts: 297
edited 2011-06-02 17:01 in Robotics
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
1024 x 768 - 117K
1024 x 768 - 64K
1024 x 768 - 93K
1024 x 768 - 93K
1024 x 768 - 94K
1024 x 768 - 83K
1024 x 768 - 153K
1024 x 768 - 58K
1024 x 768 - 88K
Sign In or Register to comment.