// Duelling Tones - Simultaneous tone generation.
// To mix the output of the signals to output to a small speaker (i.e. 8 Ohms or higher),
// simply use 1K Ohm resistors from each output pin and tie them together at the speaker.
// Don't forget to connect the other side of the speaker to ground!
// This example plays notes 'a' through 'g' sent over the Serial Monitor.
// 's' stops the current playing tone. Use uppercase letters for the second.
#include <Tone.h>
int notes[] = { NOTE_A3,
NOTE_B3,
NOTE_C4,
NOTE_D4,
NOTE_E4,
NOTE_F4,
NOTE_G4 };
int lightPin1 =
5; //define a pin for Photo resistor
int lightPin2 = 3; //define a pin for Photo resistor
int lightPin3 = 1; //define a pin for Photo resistor
int reading;
// You can declare the tones as an array
Tone speaker;
void setup(void)
{
Serial.begin(9600);
speaker.begin(8);
}
void loop(void)
{
reading = analogRead(lightPin1);
if(reading < 50) speaker.play(220,500);
else speaker.stop();
reading = analogRead(lightPin2);
if(reading < 50) speaker.play(240,500);
else speaker.stop();
reading = analogRead(lightPin3);
if(reading < 50) speaker.play(280,500);
else speaker.stop();
}
Hello !!
I'm making a little laser harp and i've just tried the source code above with 3 lasers ,3 photoresistors and one speaker and works great !
I just have one question....
How can i make the notes
fade away
(i hope that's the correct word).For example if i interrupt one of the
laser beams i want a note to be played and when i remove my hand from the laser beam i want the note to stop slowly and not directly(something like the acoustic guitar).As you understand i want the laser beams to work like the strings of a guitar.Is that possible to make it ? I 'm using the tone library that i found in the arduino playground.Is there any library that has notes tha sound like the notes of a guitar ?
Thanks in advance !!!