Hi! I created a small project - radio control machine, based on the RC-Switch lib. The main idea is that I have several radio-controlled cars and each car has its own remote control (in the code of each car it is written what values the receiver should respond to). But when debugging, I found some error - if you simultaneously press the buttons on two remote controls - the cars do not go and the receiver cannot receive the signal, but if you press these buttons with a difference of half a second - the cars move.
I analyzed the signal receiving code and I think I found the problem.
#include <RCSwitch.h> //RF receive lib
#include <Arduino.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(1); // receiver must be connected to digital pin 3 (enable RF receiver)
}
void loop() {
if (mySwitch.available()) { //if there is any data in buffer
unsigned long start;
start = mySwitch.getReceivedValue();
Serial.print("start:");
Serial.println(start);
}
mySwitch.resetAvailable();
}
If you press the buttons simultaneously on two remotes, there will be no output in the serial monitor.
After, I deleted clear buffer func - mySwitch.resetAvailable();
and put instead delay(20);
there is an output in the port monitor - but it is not correct, instead of standard key codes, each time I received a new value.
So, I came to the conclusion that when two signals hit the receiver at the same time, the Arduino does not have time to process the first of them, and while clearing the buffer, the second signal gets to the receiver, so there is no output in the port monitor.
If you have any ideas how to solve this problem, I will be very glad to help, thanks in advance!