Go Down

Topic: different tones on different speakers simultaneously? (Read 2684 times) previous topic - next topic


I am using an UNO for my project.
My project is a musical instrument that generates a tone when the divided voltage reading through a photo-resistive cell dips below a threshold. There are multiple sensors, each with its own speaker. The problem I am having is that when one tone initiates on one speaker, no other tone will play on the other speakers. I believe there should be no problem generating 2 or more distinct PWM signals to the speakers. I have looked at manipulating the PWM frequencies more directly, but I believe I am limited by the discrete set of divisors.

This is a stub of the code to illustrate the scheme, and perhaps highlight any causes of my problem:

void setup() {}
void loop() {
if (sensor1 < threshold1) tone(outputPin1, frequency1, duration1)
if (sensor2 < threshold2) tone(outputPin2, frequency2, duration2)

If I trigger the sensors simultaneously, the first tone to play will continue to do so until the trigger action is disengaged, while the other remains silent. My desire is to get any speaker to play at any time, regardless of other speakers playing.

Coding Badly


I believe the standard tone library provide in the Arduino distribution can only have one tone active at a time. There however is a nice user contributed library available for downloading, but sadly it's also named tone.  ;)
Anyway it can generate as many as 3 tones at a time on a 328p based board and up to 5 tones at a time on a mega board.



Go Up