Go Down

Topic: playing more then two tones Simultaneously (Read 710 times) previous topic - next topic

ori

Feb 18, 2012, 02:56 pm Last Edit: Feb 25, 2012, 11:37 pm by ori Reason: 1
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);
 
 
}



yorx

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

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

ori

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


Go Up