Hi !!!
I am building a laser harp project and at first i was using one and only speaker.My project has 6 laser strings so it has to play six notes. I decided to connect 6 speakers,one for each one of the lasers so that every speaker plays only one note.The problem is that i can't use more than three digital pins.How i understood that ??? In the code below as you see i am using pins 3-8 one for each speaker.
when i run the program the only speakers that producing the tones are the first three (pin 3, pin 4 and pin 5).But if i change the code like the one that is on the right again only the first three pins are working (pin 3,pin 8 amd pin 7).Why this is happening ????
void setup(void)
{
Serial.begin(9600);
aSpeaker1.begin(3); // first speaker at digital pin 3 aSpeaker1.begin(3);
aSpeaker2.begin(4); // second speaker at digital pin 4 aSpeaker2.begin(8);
aSpeaker3.begin(5); // third speaker at digital pin 5 aSpeaker3.begin(7);
aSpeaker4.begin(6); // fourth speaker at digital pin 6 aSpeaker4.begin(6);
aSpeaker5.begin(7); // fifth speaker at digital pin 7 aSpeaker5.begin(5);
aSpeaker6.begin(8); // sixth speaker at digital pin 8 aSpeaker6.begin(4);
}
Here is the full source code of my project
#include <Tone.h>
int notes[] = { NOTE_A3,
NOTE_B3,
NOTE_C4,
NOTE_D4,
NOTE_E4,
NOTE_F4,
NOTE_G4 };
int lightPin1 = 0; //define a pin for Photo resistor
int lightPin2 = 1; //define a pin for Photo resistor
int lightPin3 = 2; //define a pin for Photo resistor
int lightPin4 = 3; //define a pin for Photo resistor
int lightPin5 = 4; //define a pin for Photo resistor
int lightPin6 = 5; //define a pin for Photo resistor
int reading;
// You can declare the tones as an array
Tone aSpeaker1;
Tone aSpeaker2;
Tone aSpeaker3;
Tone aSpeaker4;
Tone aSpeaker5;
Tone aSpeaker6;
void setup(void)
{
Serial.begin(9600);
aSpeaker1.begin(3); // first speaker at digital pin 3
aSpeaker2.begin(4); // second speaker at digital pin 4
aSpeaker3.begin(5); // third speaker at digital pin 5
aSpeaker4.begin(6); // fourth speaker at digital pin 6
aSpeaker5.begin(7); // fifth speaker at digital pin 7
aSpeaker6.begin(8); // sixth speaker at digital pin 8
}
void loop(void)
{
reading = analogRead(lightPin1);
if(reading < 50) // when the laser hits the photoresistor the value of the photoresistor goes to 280 and when not hit goes to 20.
{ // So if reading goes under 50 (that means that the laser beam is interupted)
aLaser1.play(130,400); // produce 130 Hz for 400 msecond to the first speaker.
}
reading = analogRead(lightPin2);
if(reading < 50)
{
aLaser2.play(140,400);
}
reading = analogRead(lightPin3);
if(reading < 50)
{
aLaser3.play(160,400);
}
reading = analogRead(lightPin4);
if(reading < 50)
{
aLaser4.play(170,400);
}
reading = analogRead(lightPin5);
if(reading < 50)
{
aLaser5.play(190,400);
}
reading = analogRead(lightPin6);
if(reading < 50)
{
aLaser6.play(200,400);
}
}