Pages: [1]   Go Down
Author Topic: different tones on different speakers simultaneously?  (Read 1039 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There are multiple sensors, each with its own speaker.

How many?
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16549
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-wink
 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.

http://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

Lefty
Logged

Pages: [1]   Go Up
Jump to: