Hi, I am new to the forum and the Arduino platform, I have an idea for a project that is in need of some guidance. I want to recreate songs by programming the notes and duration in Arduino and have it output through a piezo speaker. I have done this successfully on a lesser scale; however, I was wondering if it would be possible to have the arduino play large chords IE like a piano or guitar by sending multiple signals to multiple piezo speakers. I would probably need about 4-5 speakers to recreate the playing of a simple piano song. Any advice would be greatly appreciated!
There is Tone Library that discusses having multiple instances of Tone being generated in a non-blocking method to do that.
http://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation
I wrote this code to play 4 tones on 4 piezos one after the other while a switch on pin 3 (with internal pullup enabled) was grounded.
while (digitalRead(3) == LOW){
for (int i=0; i <= 511; i++){
digitalWrite(4, HIGH);
delayMicroseconds(500);
digitalWrite (4, LOW);
delayMicroseconds(500);
}
delay(10);
for (int i=0; i <= 511; i++){
digitalWrite(5, HIGH);
delayMicroseconds(460);
digitalWrite (5, LOW);
delayMicroseconds(460);
}
delay(10);
for (int i=0; i <= 511; i++){
digitalWrite(6, HIGH);
delayMicroseconds(420);
digitalWrite (6, LOW);
delayMicrose6conds(420);
}
delay(10);
for (int i=0; i <= 511; i++){
digitalWrite(7, HIGH);
delayMicroseconds(380);
digitalWrite (7, LOW);
delayMicroseconds(380);
}
delay(10);
}
You could adapt something like this to run blink without delay style checking every 100uS or so to see if a button was pressed for a note, and if so if the time interval had passed to change high/low output status of the note.