I'm writing a IR application for Arduino which receives IR signals from another Arduino board and move two motors in according with the commands received.
The problem is that if the IR application loses the IR signals, motors doesn't stop but keep running following the last received command.
I tried to check if there are no other IR signals (it means that the board lost the signal) and then i stop the motors in this way:
void loop() {
if (irrecv.decode(&results)) {
// process data
}
else {
//stop motors;
}
this solution works but since the IR signals are sent within a ms interval, it happens that motors doesn not work continously when IR signals are sent.
So i'd like to do something like this:
void loop() {
if (irrecv.decode(&results)) {
// process data
}
else if( !(irrecv.decode(&results) && time_elapsed > interval){
//stop motors;
}
but how i can implement this?
Can you give me some suggestions, please?