Help with the Tone Library

Greetings,

I'm making a piano where lasers are shining on photoresistors, and when the laser beam is blocked, the resistance is high and the Audino plays a note. I have 13 of these attached to a Mux shield on the Arduino where each of them plays a different note. Using the Tone Library, what would be the easiest way to tell the Arduino that if two lasers are blocked, play two notes, or three lasers and three notes? I could write out every possible combination, but that would take much too long. Could someone please give me some sample code to work with?

Best regards, Charles

https://www.arduino.cc/en/reference/tone

Does it allow you to play multiple notes at once?

Yes. It uses one output pin to play one note, and two output pins to play two notes. So if I wanted to play C4 and E4, I would say:

#include <Tone.h>
Tone tone1;
Tone tone2;


void setup() {
tone1.begin(13);
tone2.begin(9);
}

void loop() {
tone1.play(NOTE_C4);
tone2.play(NOTE_E4);
}

Two notes sound okay, three notes sounds a bit fuzzier, and four notes sound very bad.

You could use the code I created here, replace the button readings with your laser/resistor, to select the one or more notes played. http://forum.arduino.cc/index.php?topic=179761.0

I am a beginner with the Arduino, so I'm not sure how I would replace button readings with the resistor readings. Does your code work with the Arduino Uno? I see many things in your code that I have never encountered before. Sorry if my lack of knowledge seems frustrating, but any help would be appreciated.

Could someone please help me out with this?

The real answer to reply #1 is no the tone library can not play more than one note at one time.

You need a library that will do this, this library is not the tone library, search google to see if you can find one that can do this. You have already been given one such link.

I have searched on Google and the only library that I have found is the Tone library. Maybe you could suggest a library in specific?

charles_kitchener: I have searched on Google and the only library that I have found is the Tone library. Maybe you could suggest a library in specific?

What words are you using? Try Arduino polyphonic tone

There are lots out there.