i'm trying to play a passive buzzer with an IR reciver
My Code
#include <IRremote.h>
IRrecv irrecv(10);
decode_results results;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(11, OUTPUT);//buzzer
irrecv.enableIRIn();//Ir reciver at pin 10
}
int cmdex = 0;
void loop() {
// put your main code here, to run repeatedly:
if(irrecv.decode(&results)){
cmdex = 1;
Serial.println(results.value);
unsigned long data = results.value;
switch(data){
case 0xFF30CF:
noTone(11);
tone(11, 1056);
break;
case 0xFF18E7:
noTone(11);
tone(11, 571);
break;
case 0xFF6897:
noTone(11);
break;
}
irrecv.resume();
}
}
Issue
My problem is that if i use any button instead of 1 (FF30CF) 0 (FF6897) or 2 (FF18E7) the serilal port give me the right data, then when i pusch 1 the buzzer starts to play but when i push another button, the data keep changing at every push.
Serial Output FF10EF (here I push 4)
FF38C7 (here I push 5)
FF5AA5 (here I push 6)
FF30CF (here I finally push 1 and the buzzer starts to play)
(then I push 3 times 0, but the output is different from the expected FF6897 and the buzzer doesn't stop)
D965AA42
EB670632
AB03A967
Note
- I'm using the IRremote.h library
-
2does IRremote use Timer2 used by tone()?Juraj– Juraj ♦09/05/2021 19:36:07Commented Sep 5, 2021 at 19:36
-
1as per @Juraj comment ... please refer to stackoverflow.com/questions/62832918/function-tone-and-irremotejsotola– jsotola09/05/2021 21:01:09Commented Sep 5, 2021 at 21:01