What is an Arduino?
So, before I get into how I employed an Arduino to produce the sound effects and coordinate the lighting, I'll get you up to speed as to what, exactly, is an Arduino.
In technical terms, an Arduino is a combination of a programmable microcontroller and a circuit board containing everything needed to interface to it with a standardized pinout.
In simpler terms, think of it as a mini computer you can send computer code to to instruct it what to do with all those pins.
On its own, the Arduino isn't capable of a whole lot, except send or receive data or voltage to its pins. And can only really send 3.5V or 5V at that. But it can be extended using "shields" which are basically additional circuit boards that can stack and slot into those standardized pin layouts. They'll often come with a "library" [ think 'chunk of code that translates complicated interface stuff into commands like do_the_thing()' ] to make things easier on you.
In the case of the Proton Pack, I'll be employing an Arduino and a Wave Shield, which extends the Arduino so that it can read sound effects from an SD card and gives me simple programming control over when/how.
The Wave Shield
I already had an Arduino on hand for a while now, but I ordered a Wave Shield from Spikenzielabs. Only issues is they come unassembled. Thankfully, they're all through-hole components, easy to solder [ Note to self: an Exordium on soldering should be written ].
Soldering is really easy, especially through-hole soldering [ trust me, it really is ], and the shield itself indicated exactly what went where component wise, but this was still a couple hours worth of project time.
After which I plugged it atop the Arduino.
So, to use an Arduino, you download the software IDE [ "Integrated Development Environment" ] from https://www.arduino.cc. The Arduino site itself has plenty of great tutorials on getting started, so I'll only deal with it peripherally here.
I also download the Wave Shield library from https://github.com/adafruit/WaveHC and extract it to the Arduino library directory,.
Basically, I run the software, tell it I'm using an "Uno" board(because I am) and I download the Wave Shield library path [ on Windows, this is by default in C:\Users\$USER\Documents\Arduino\libraries ]. I also go to "Sketch"->"Import Library" and import the WaveHC library.
To test the board, I downloaded and opened and uploaded to the Arduino the main "play6" example at the helpful Adafruit page. I used a 'breadboard" and some jumper wire to a dipswitch set to test that connecting some of the pins to ground produced the sound of the expectedly named MP3s on the SD card. I sadly don't have a video of this.
The example did enlighten me to a new limitation of the Wave Shield: It can only ever play one sound at a time and must play the sample to completion before I can check the button states again. Which means I'd need the following sound samples:
I won't bother with a wand winding down noise.
Since the example already did a thing I wanted, namely play a sound at the press of a button, I simply modified it to do what I needed it to to accommodate the following
When programming, it sometimes helps to put things in a flowchart to plan out the logic. Google provides free flowcharting tools within their Google Drive tools at http://drive.google.com. Create a new "Google Draw" document and use the shape or line buttons to insert stuff. Works great.
Another limitation is that I can only realistically read the button states once in that cycle if I want the code to stay sane. So whatever I do, I need to combine all button inputs into a single call.
Ok, let me explain that last statement.
Arduinos are coded in the C programming language, which is a basic "imperative" language. This means that commands can call "functions" which are themselves blocks of other commands, which helps both simplify things as well as isolate one set of commands from the overall flow, making it easy to fix, troubleshoot or change later.
Basically, code is structured like this:
// this is a comment to help you read code because it starts with '//'
That's pretty much as far as I'll go insofar as how to program in C is concerned. There are lots of references out there, such as at http://www.cprogramming.com.
Suffice it to say. to read all the buttons in one cycle and get some I can use in a C switch() statement [ think of this as a literal multi-setting switch in which, based on the value of an integer, things happen, so if the integer is 0, one thing happens, 1, another thing happens, etc... ], I would need to have a function that would read all the button states and return a single value, rather than have a different value for each switch.
So hitting button 1 but not 2 would return a value different than hitting just button 1 or 2. Etc...
I copied part of this from some stackoverflow.com answer but I can't find it anymore.
// You don't need to know exactly what I'm doing here, but basically, i'm using
For the actual audio, I used Audacity, a free audio editing program, that's pretty easy to use. The original audio was grabbed from Googling and coming across http://hprops.com/sounds/.
The pack running noise is fairly short, since it just gets looped again and again. Also, due to the fact that the audio must play until the end, having it run too long means a delay from switching off the pack to the pack stopping noise.
So, another thing to note is that a few of the Arduino pins are used by the Wave Shield in order to talk about the Arduino. As such, I picked the ones which weren't in use for the buttons. Pins 14 and 15 would be the pack switch and wand button.
Pins 6, and 9 would give out 5V [ you'll see this in the code as being set to HIGH ] while the pack is running to power the LED circuits. Pin 7 would power the colour changing LED at the tip of the wand while it's firing.\
Arduino "sketch" [ the C code minus the libraries ]
A reminder that the code above is simply a modified version of the code available at Adafruit. It was roughly shoehorned in shape, so there's plenty in there I'm not even using. I commented the bits I added in, though, to make it a little easier.
Finally, I used an amplified battery powered speaker I bought from Wal-Mart years ago as the main pack amplifier speaker since it had a lot of oomf and could be powered by easily changeable AAAs. The Arduino itself would be powered, eventually, by a USB phone charger lithium pack which should power it for at least a day of con-walking [ Arduinos are really easy on power consumption ].
All put together, this is what it sounded like! [ ignore the LED bits, that'll be on the next post ].
So, that pretty much does it for the Arduino post. The sound brains are done, all that remains is the lighting and wiring and touch up stuff which we'll cover in the next few posts. Ta ta for now!
"Inside every sane person there’s a madman struggling to get out."
Réal is a jackass of all trades, master of none, with interests in politics, human interface design, animation, video games, VR, technology, and making random stuff. Has a skill to have both too much time on his hands and nowhere near enough to get stuff done.