Pages: [1]   Go Down
Author Topic: playing more then two tones Simultaneously  (Read 664 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
im working on a code that generate sound that changes with relation to climate change using an SHT15 temp and humidity sensor and a small speaker.

i dont get why it wont work, the moment im adding another tone.
would love a bit of assistance

cheers //
ori.

this is the code:

/*
*
*/

#include <SHT1x.h>
#include <Tone.h>
#define dataPin  10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);
Tone tone1;
Tone tone2;
/*
Tone tone3;
Tone tone4;
*/

void setup()
{
  
  tone1.begin(9);
  
  tone2.begin(9);
  /*
  tone3.begin(6);
  
  tone4.begin(6);
 */
  Serial.begin(38400);
   Serial.println("Starting up");
}

void loop()
{
  float temp_c_p1;
  float humidity_p1;
  float temp_x;
  float humidity_y;
  
  temp_c_p1 = sht1x.readTemperatureC();
  humidity_p1 = sht1x.readHumidity();
  
  temp_x = (temp_c_p1*5/20);
  humidity_y = (humidity_p1*3/70);

    
  tone1.play((127+temp_x),1500);
  
  tone2.play((440+(227*humidity_y)),1500);
  /*
  tone3.play((198*humidity_y+440),1500);
  
  tone4.play((107+temp_x),1500);
  */
  Serial.print("Temperature: ");
  Serial.print(temp_c_p1);
  Serial.print("C / ");
  Serial.print(". Humidity: ");
  Serial.print(humidity_p1);
  Serial.println("%");
  

  delay(100);
  
  
}


« Last Edit: February 25, 2012, 05:37:20 pm by ori » Logged

Madrid
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino on the rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

try to insert a delay after each toneX.play to determine the length of the sound

seems to work with Mario smiley-wink: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1253920105
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the idea was to try and play more than two tones at the same time
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31548
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you seen this:-
http://wiki.animusoft.com/tutorials/arduino-tutorials/arduino-digital-ports-tutorials/arduino-playing-tones-on-multiple-outputs-using-the-tone-function-example/
Logged

Pages: [1]   Go Up
Jump to: