problem using IRreceive & tone() in same Arduino sketch

Thread Starter

flat5

Joined Nov 13, 2008
403
Maybe I can get help in this forum.
Proper numbers are returned except when the 'tone' function is added.
After first time only '0' is returned.
Code:
/*
IR_remote_detector sketch
An IR remote receiver is connected to pin 11. Have tried 2-6 & 11.
Decode problem when using tone function. Always returns 0 after first time.
The LED on pin 13 toggles each time a button on the remote is pressed.
*/

#include <IRremote.h>                    //adds the library code to the sketch

const int irReceiverPin = 11;            //pin the receiver is connected to
const int ledPin = 13;

IRrecv irrecv(irReceiverPin);            //create an IRrecv object
decode_results decodedSignal;         //stores results from IR detectorvoid setup()
unsigned long value;
void setup ()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
irrecv.enableIRIn();                   // Start the receiver object
}

boolean lightState = false;     //keep track of whether the LED is on
unsigned long last = millis();  //remember when we last received an IR message

void loop()
{
if (irrecv.decode(&decodedSignal) == true) //this is true if a message has
                                            //been received
{
 value = decodedSignal.value;
   delay(200); // extra debounce
 Serial.print(value);
 Serial.print("  ");


 tone(8,600,100);   // comment out this line and the IR receiver works as expected!


 if (millis() - last > 250) {       //has it been 1/4 sec since last message? debounce?
   lightState = !lightState;              //Yes: toggle the LED
   digitalWrite(ledPin, lightState);
 }
 last = millis();
 irrecv.resume();                         // watch out for another message
}
}
 

Thread Starter

flat5

Joined Nov 13, 2008
403
Thank you, JWH! My Google searches found nothing useful.
I thought it was an interrupt problem but what do I know :)
It gives me a place to start. I'm reading about it all...

First I'll try another IR library but what I'm reading is they may all have the problem without modification.
 
Top