Toymaker Television

Daily content for the geek and DIYer



72 notes &

Coding a Heartbeat Part III

Goal: To code a heartbeat (audio/visual) that increases in rate and volume as you “get closer” and have it decrease in rate and volume as you “back away”

So now that we have the LEDs blinking according to a heartbeat, I’ve got to somehow get the sound to work the same way!

Step 4

So using the Object Exchange on Parallax’s website - and this is a repository of code that other people have written that allow you to not have to reinvent the wheel - @RoyEltham kindly gave me code that plays WAV files.

http://obex.parallax.com/objects/324/

At first I googled for heartbeat sounds, but after cutting them down and making them 16k Hz, they were all sorts of noisy and digitally distorted.  So I just used Audacity’s “Risset Drum” sound making thing to make a thump:

Don’t forget, to use this object you need to set the file to 16000Hz and when you save it, save it to Unsigned 8-bit PCM WAV file.  Otherwise, it won’t work and you’ll act like me and whine!

Here’s the code that incorporates the OBJ (object like RCTime and PST) for playing WAV files:

And now!  We have it so that whenever the LED lights up, the sound comes up too.  I believe the last step is the packaging and using non-demoboard LEDs to light something creepy up :D.

@atdiy/@tymkrs

Filed under object exchange propeller spin wav files wav file with microcontroller heart beat audacity rc time obj parallax serial terminal tymkrs electronics programming for dummies

  1. estelle-young reblogged this from tymkrs
  2. tymkrs posted this