As usual when working with MikroElektronika boards all hardware aspects are extremely easy to implement: just place the MP3 click into socket A of the Flip & Click board. Place one IR distance click into socket B. The second IR distance click is connected to socket C, using an extension cable (you might recognize the adapter made with one PROTO click from the line follower project). Only 3.3V, GND and AN lines are used for the second IR click.
Unlike the original theremin, which varies pitch continuously, this Arduino-based version generates discrete musical notes, but with a bit of polyphony and a bit of reverb it’s quite close to what the original can do. I’ve also tried to emulate the way an orioginal theremin is controlled, with the left hand controlling volume, and right hand used to change the pitch.
Parts of this code are inspired from the MP3_Shield_RealtimeMIDI.ino code. Most notably, the plugin sequence used to put the VS1053 in real-time MIDI mode using SPI is taken from the VLSI Solutions patch page.
Once the MP3 click is placed into real-time MIDI mode we start monitoring the two IR distance click boards, taking an average of four measurements for each sensor. Considering the characteristics of the GP2Y0A60SZ0F sensor I’ve cut down the extremes, and the code also detects if there is no hand in front of the theremin.
Then, the values for note and volume are scaled into a more useful range, to meet the specifications of the VS1053.
With the above consideration, the code listing is:
From here you can change the instrument, change the lowest and the highest note that can be played. You’ll find that some instruments sound better, some others don’t. Try them all.
I was thinking to put a small video with the theremin in action, but it turns out I’m a total disaster when it comes to playing music. So, instead, I will leave you with a true theremin virtuoso: http://youtu.be/K6KbEnGnymk