7
I’m making a bell with Andy. This bell shall be composed of:
- 01 Arduino UNO,
- 01 Buzzer,
- 01 Transmitter 433 Mhz,
- 01 Receptor 433 Mhz.
My doubt revolves around how I can treat the listener who will be listening the control controls 433 Mhz and at the same time make the treatment to that Buzzer oscillates using delays.
My code is basically this. I am using the Rfremote library I found in this link https://github.com/renatoaloi/RFremote
#include <RFremote.h>
SignalPatternParams params;
RFrecv rfrecv;
int status_prog = 0;
const int buzzer = 11;
const char *BOTAO1 = "0100100100110110110100100110110100100110110110110110100100110100100110100100110100110";
const char *BOTAO3 = "0100100100110110110100100110110100100110110110110110100100110100100100110100110100110";
void setup()
{
Serial.begin(9600);
delay(500);
Serial.println("INICIADO!");
// COMPATEC remote
params.spaceMin = 10000;
params.spaceMax = 15000;
params.dotMin = 450;
params.dotMax = 600;
params.traceMin = 950;
params.traceMax = 1150;
params.skipFirst = 0;
params.skipLast = 0;
rfrecv = RFrecv(¶ms);
rfrecv.begin();
pinMode(buzzer,OUTPUT);
}
void loop()
{
if (rfrecv.available()) // LISTENER DO CONTROLE - RECEBE ID DO CONTROLE/TECLA VIA FREQUENCIA 433 Mhz
{
if (strncmp((char*)rfrecv.cmd, BOTAO1, CMD_SIZE) == 0) {
status_prog = 1; // LIGA O BUZZER
}
if (strncmp((char*)rfrecv.cmd, BOTAO3, CMD_SIZE) == 0) {
status_prog = 3; // DESLIGA O BUZZER
}
}
if(status_prog == 1) { // SE O BOTÃO PRESSIONADO FOR EQUIVALENTE A 1 LIGA
tone(buzzer, 650); // ACIONA BUZZER COM A TONALIDADE 650
delay(400); // PAUSA POR 400 MS
noTone(buzzer); // DESLIGA BUZZER
delay(400); // PAUSA POR 400 MS
}
if(status_prog == 3){
noTone(buzzer); // SE O BOTÃO PRESSIONADO FOR EQUIVALENTE A 3 DESLIGA
}
}
If I remove the delay in this part
if(status_prog == 1) { // SE O BOTÃO PRESSIONADO FOR EQUIVALENTE A 1 LIGA
tone(buzzer, 650); // ACIONA BUZZER COM A TONALIDADE 650
//delay(400); // PAUSA POR 400 MS
//noTone(buzzer); // DESLIGA BUZZER
//delay(400); // PAUSA POR 400 MS
}
the program works correctly.
I think the delay(400)
ends up taking the time that the program as a whole has to listen to the control. What would be the approach to take in this case? A Thread would be welcome...