![]() Now, think back to physics, and recall that period = 1/frequency. ![]() While the tone() function can only be run one instance at a time, I discovered (after much research), that I could hijack one of the timers (again, I chose timer2), and use some clever math and software interrupts to generate 5 tones simultaneously! I wanted to generate 5 tones of the following frequencies:Īny music lovers out there will surely recognize this as the pentatonic scale (5 notes that nearly always sound good together). But I wanted to make 5 tones simultaneously! How to do it? So you naturally loose that ability when using the tone() function. Specifically, it uses timer2, which is also responsible for controlling PWM on pins 3 and 11. ![]() It relies on one of the arduino’s 3 timers to work in the background. The built-in tone() function allows you to generate a square wave with 50% duty cycle of your selected frequency on any pin on the arduino. Unfortunately, none of these generated tones as nice as the ones I got when simply using the arduino tone library. I examined several methods for generating the 5 square waves in hardware – using a 555 timer, oscillating RC with schmitt trigger, and a bunch of opamp circuits. ![]() I’m working on a project where I want to drive 5 speakers independently – each with a variable volume and set frequency (though the frequency of each speaker is different). Mimi Yin has a neat implementation of this code for an interactive sculpture. This post was featured on the Hack-a-Day Blog on 9/14/10
0 Comments
Leave a Reply. |