Show Posts
Pages: [1] 2
1  Using Arduino / Installation & Troubleshooting / Re: Digital Pins Problem on: January 27, 2011, 03:11:54 pm
I ve figured how to make my laser harp playing a little better than before.You see my problem was that when i had one speaker for producing the notes,when i interrupt one and only laser beam the tone played well.But when i was interrupting two laser beams at the same time the notes for each interrupted beam was played at the same time from the one and only speaker and the mixing of the two tones was awfull. Now i 've conncted 3 speakers and i have 6 laser beams. The first laser goes with speaker 1 ,the second laser goes with speaker 2 ,the third laser goes with speaker 3, the fourth lase goes with speaker 1, the fifth laser goes with speaker 2 and the sixth laser goes with speaker 3.The only problem is when i hit at the same time the laser 1 and 4 together or the laser 2 and 5 together or the laser 3 and 6 together because these pairs are using the same speaker. So i've changed my source code a little and if one of the 3 combinations comes up a totally different sound is played by the speaker connected with the pair.

Code:
#include <Tone.h>

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;
int reading2;

// You can declare the tones as an array

Tone aLaser1;
Tone aLaser2;
Tone aLaser3;
Tone aLaser4;
Tone aLaser5;
Tone aLaser6;

void setup(void)
{
  Serial.begin(9600);
  aLaser1.begin(3);
  aLaser2.begin(4);
  aLaser3.begin(5);
}

void loop(void)
{
  reading = analogRead(lightPin1);
  if(reading < 50)
  {
    aLaser1.play(130,400);
  }
 
  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)
  {
    aLaser1.play(170,400);
  }
 
  reading = analogRead(lightPin5);
  if(reading < 50)
  {
    aLaser2.play(190,400);
  }
 
  reading = analogRead(lightPin6);
  if(reading < 50)
  {
    aLaser3.play(200,400);
  }
 
 
  ////////////////////////////////////////////////////
  //         This is the code for the combinations          //
  ////////////////////////////////////////////////////

  reading = analogRead(lightPin6);
  reading2 = analogRead(lightPin3);

  while(reading < 50 && reading2 < 50)
  {
    aLaser3.play(220,400);
   
       reading = analogRead(lightPin6);
       reading2 = analogRead(lightPin3);
       if(reading >50 || reading2 >50)
       aLaser3.stop();
  }
 
 
  reading = analogRead(lightPin5);
  reading2 = analogRead(lightPin2);
  while(reading < 50 && reading2 < 50)
  {
    aLaser2.play(240,400);
   
       reading = analogRead(lightPin5);
       reading2 = analogRead(lightPin2);
       if(reading >50 || reading2 >50)
       aLaser2.stop();
  }
 
 
  reading = analogRead(lightPin4);
  reading2 = analogRead(lightPin1);
  while(reading < 50 && reading2 < 50)
  {
    aLaser1.play(260,400);
   
       reading = analogRead(lightPin4);
       reading2 = analogRead(lightPin1);
       if(reading >50 || reading2 >50)
       aLaser1.stop();
  }
       
}//void loop

2  Using Arduino / Programming Questions / Re: Digital Pins Problem on: January 27, 2011, 02:37:03 pm
I ve figured how to make my laser harp playing a little better than before.You see my problem was that when i had one speaker for producing the notes,when i interrupt one and only laser beam the tone played well.But when i was interrupting two laser beams at the same time the notes for each interrupted beam was played at the same time from the one and only speaker and the mixing of the two tones was awfull. Now i 've conncted 3 speakers and i have 6 laser beams. The first laser goes with speaker 1 ,the second laser goes with speaker 2 ,the third laser goes with speaker 3, the fourth lase goes with speaker 1, the fifth laser goes with speaker 2 and the sixth laser goes with speaker 3.The only problem is when i hit at the same time the laser 1 and 4 together or the laser 2 and 5 together or the laser 3 and 6 together because these pairs are using the same speaker. So i've changed my source code a little and if one of the 3 combinations comes up a totally different sound is played by the speaker connected with the pair.

Code:
#include <Tone.h>

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;
int reading2;

// You can declare the tones as an array

Tone aLaser1;
Tone aLaser2;
Tone aLaser3;
Tone aLaser4;
Tone aLaser5;
Tone aLaser6;

void setup(void)
{
  Serial.begin(9600);
  aLaser1.begin(3);
  aLaser2.begin(4);
  aLaser3.begin(5);
}

void loop(void)
{
  reading = analogRead(lightPin1);
  if(reading < 50)
  {
    aLaser1.play(130,400);
  }
  
  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)
  {
    aLaser1.play(170,400);
  }
  
  reading = analogRead(lightPin5);
  if(reading < 50)
  {
    aLaser2.play(190,400);
  }
  
  reading = analogRead(lightPin6);
  if(reading < 50)
  {
    aLaser3.play(200,400);
  }
  
  
  ////////////////////////////////////////////////////
  //         This is the code for the combinations          //
  ////////////////////////////////////////////////////

  reading = analogRead(lightPin6);
  reading2 = analogRead(lightPin3);

  while(reading < 50 && reading2 < 50)
  {
    aLaser3.play(220,400);
    
       reading = analogRead(lightPin6);
       reading2 = analogRead(lightPin3);
       if(reading >50 || reading2 >50)
       aLaser3.stop();
  }
  
  
  reading = analogRead(lightPin5);
  reading2 = analogRead(lightPin2);
  while(reading < 50 && reading2 < 50)
  {
    aLaser2.play(240,400);
    
       reading = analogRead(lightPin5);
       reading2 = analogRead(lightPin2);
       if(reading >50 || reading2 >50)
       aLaser2.stop();
  }
  
  
  reading = analogRead(lightPin4);
  reading2 = analogRead(lightPin1);
  while(reading < 50 && reading2 < 50)
  {
    aLaser1.play(260,400);
    
       reading = analogRead(lightPin4);
       reading2 = analogRead(lightPin1);
       if(reading >50 || reading2 >50)
       aLaser1.stop();
  }
      
}//void loop

3  Using Arduino / Installation & Troubleshooting / Re: Digital Pins Problem on: January 27, 2011, 10:43:53 am
you don't need 3 (or 6) speakers; use a simple audio mixer circuit instead.

How does it work the audio mixer circuit ???
Is there anything in the forum about the audio mixer circuit that i can find ?
4  Using Arduino / Programming Questions / Re: Digital Pins Problem on: January 27, 2011, 09:57:39 am
How about this .. do they play?

Code:
void loop(void)
{
    aSpeaker4.play(170,400);
    aSpeaker5.play(190,400);
    aSpeaker6.play(200,400);
      
}

Same thing again.

The problem is when i declare the pins for each speaker.
It uses the first three pins that i have them in Bold (pin 3 ,pin 4 and pin 5)

Quote
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                          
}

If i change the declaration of the pins to the following , again it uses the first three pins (pin 8 ,pin 7 amd pin 6)

Quote
void setup(void)
{
  Serial.begin(9600);

  aSpeaker1.begin(8 ); // first speaker at digital pin 8                          
  aSpeaker2.begin(7); // second speaker at digital pin 7                      
  aSpeaker3.begin(6); // third speaker at digital pin 6

  aSpeaker4.begin(5); // fourth speaker at digital pin 5                        
  aSpeaker5.begin(4); // fifth speaker at digital pin 4                          
  aSpeaker6.begin(3); // sixth speaker at digital pin 3                          
}

If i have three speakers connected to 8 ,7 and 6 pins they produce sound ,but if i take the cable from pin 7 and connect it to pin 4 or 3 or 5 only the speakers at pin 8 and 7 will continue playing
5  Using Arduino / Installation & Troubleshooting / Re: Digital Pins Problem on: January 27, 2011, 09:43:41 am
I believe there are only 3 hardware timers and so only 3 "PM-Like" functions at one time.. Perhaps that is the limitation you are experiencing...

Is there any way to make it work with 6 speakers ???
6  Using Arduino / Programming Questions / Re: Digital Pins Problem on: January 27, 2011, 09:43:02 am
The best way to chop this in 1/2 is to print out the values you are getting to the serial monitor.

Also - I would remove the if statements and just test them all with very simple code and see if that works.
Code:
void loop(void)
{
    aSpeaker1.play(130,400); // produce 130 Hz for 400 msecond to the first speaker.
    aSpeaker2.play(140,400);
    aSpeaker3.play(160,400);
    aSpeaker4.play(170,400);
    aSpeaker5.play(190,400);
    aSpeaker6.play(200,400);
       
}
Using this technique, you should be able to determine if the problem is a limit or code logic / values being read, etc.



Nope same thing happens only the first three are playing
7  Using Arduino / Installation & Troubleshooting / Re: Digital Pins Problem on: January 27, 2011, 09:08:44 am
Which version of the IDE are you using? Which Arduino?


I am using Arduino Duemilanove.

Quote
According to Tone.cpp, only one pin can be used as a Tone pin at any given time.

According to this i could only play tones with one speaker but in my case i have three speakers working.
Can you tell a solution for my prblem ?

I've just read the changelog of the tone library and if you see at 0002 it says FIxed:Multiple pins.

Quote
$Id: changelog.txt 120 2010-07-17 19:01:15Z bhagman@roguerobotics.com $

Tone Library

Version Modified By Date     Comments
------- ----------- -------- --------
0001    B Hagman    09/08/02 Initial coding
0002    B Hagman    09/08/18 Fixed: Multiple pins.
0003    B Hagman    09/08/18 Fixed: Moved initialization from constructor to
                                    begin().
0004    B Hagman    09/09/26 Fixed: Problems with ATmega8.
0005    B Hagman    09/11/23 Fixed: Scanned prescalars for best fit on 8 bit
                                    timers
                    09/11/25 Fixed: Pin toggle method to XOR.
                    09/11/25 Fixed: timer0 from being excluded.
0006    B Hagman    10/03/21 Fixed: License updates, minor fixes.
        B Hagman    10/07/17 Fixed: (more) problems with ATmega8 (thanks to Pete62)
8  Using Arduino / Programming Questions / Digital Pins Problem on: January 27, 2011, 09:06:54 am
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 ????

Code:
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

Code:
#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);
  }
 
       
}
9  Using Arduino / Installation & Troubleshooting / Digital Pins Problem on: January 27, 2011, 08:46:59 am
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 ????

Code:
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

Code:
#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);
  }
  
      
}
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Musical Instruments  Tone Libraries on: January 11, 2011, 05:07:24 pm
This is one video with my work so far.I hope i can find an easy solution to produce midi sounds via arduino.
[media]http://www.youtube.com/watch?v=S_mzaV2JG_M[/media]
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: Musical Instruments  Tone Libraries on: January 11, 2011, 08:48:58 am
Quote
I did a project last summer using Arduino reading analog sensors and controlling MIDI sound module. If you are after anything else but 8bit game sounds sending MIDI is the easiest way to get sounds more like a music. You do not need to get MIDI shield - it is very easy to make sending MIDI with Arduino.
Old modules are relatively cheap to get from bay and do not need computer to run. You could use computer to play your sounds too.

Thank you guys for your answers !!
Vanakaru can you tell me how exactly can i produce midi sounds via arduino ? What will i need ?
12  Forum 2005-2010 (read only) / Syntax & Programs / Musical Instruments  Tone Libraries on: December 29, 2010, 01:33:00 pm
Hi guys !!!
I am building a project and in this project the production of sounds is needed.
I found the tone library in the playground of the site but the tones are very simple.Is there any library that has tones from musical
instruments (guitar,piano etc.) ?
Thank you !!!
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: How can i make a note to fade away ??? on: January 11, 2011, 05:13:37 pm
This is one video with my work so far.I hope i can find an easy solution to produce midi sounds via arduino.

[media]http://www.youtube.com/watch?v=S_mzaV2JG_M[/media]
14  Forum 2005-2010 (read only) / Syntax & Programs / How can i make a note to fade away ??? on: November 25, 2010, 01:41:07 pm
Code:
// 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 !!!
15  Forum 2005-2010 (read only) / Interfacing / Re: How to Connect Laser Modules with Arduino on: November 24, 2010, 10:50:03 am
Code:
// 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 guys !!
I've just tried the source code above with 3 lasers and 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 interupt 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).Is that possible to make it ?
Pages: [1] 2