Go Down

Topic: Problem with Tone() function (Read 665 times) previous topic - next topic

Jausky

Feb 13, 2013, 10:46 pm Last Edit: Feb 13, 2013, 10:48 pm by Jausky Reason: 1
Hi everybody!

I've doing some testing with my Arduino board (ATMEGA2560), and I found a problem with Tone() function(Or not, maybe its my fault)

My idea was to send via IR some commands, in this case I connected an Ultrasonic Speaker(2Khz-60KHz) to the port 3, used the NECIRrcv library to decode the IR commands, and that's the code first and simple:

Code: [Select]

#include <WProgram.h>
#include <NECIRrcv.h>
#define IRPIN 8 // pin that IR detector is connected to
#define Out 3
#define Freq 5000


NECIRrcv ir(IRPIN) ;

void setup()
{
pinMode(Out, OUTPUT);      // establece el pin digital como salida
digitalWrite(Out,LOW);

Serial.begin(9600) ;
ir.begin() ;
}

void loop()
{
unsigned long ircode ;
while (ir.available()) {
ircode = ir.read() ;
Serial.print("got code: 0x") ;
Serial.println(ircode,HEX) ;
tone(Out,Freq,500);
}
}


In this code, tone always plays a 5000-Hertz frequency. But here's the problem: When tone() functions runs and finishes, the Arduino doesnt receive more signals from the IR. The loop() is still running, but it never reaches the "while(ir.available)", so Arduino only obeys me the first time I use the IR.

Another problem that I've found, when frequency growns greater 6500~7000 the speaker doesnt make any sound. I run some test and I hear frequencies to 15kHz.

If needed, the specifications for the speakers are:

Quote
Rated Voltage: 16Vp-p
   Max. Rated Long Power: 30Vp-p
   Frequency Range: approx. 2 - 60kHz
   Sound Pressure Level: max. 120dB (±15%)
   Operating Temperature: approx. -30°C - +80°C
   Weight: approx. 6g
   Diameter: approx. 41mm
   Height: approx. 12mm


Could anyone help me with this problem?

Thanks you a lot

Best regards

Go Up