I'm making a doorbell with arduino. This bell will be composed of:
- 01 Arduino ONE,
- 01 Buzzer,
- 01 Transmitter 433 Mhz,
- 01 Receiver 433 Mhz.
My question revolves around how I can handle the listener who will be listening the controls of the 433 Mhz control and at the same time make the treatment for that buzzer oscillates using delays.
My code is basically this one. I'm using the RFremote library I found at this link link
#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 that delay(400)
ends up taking the time that the program as a whole has to listen to control. What would be the approach to take in this case? An Thread would be welcome ...