This is I hope a meaningful extract showing code to wait for any communication from a 433MHz transmitter to run some functions. The result is that it will usually run the functions twice, rarely only once. I had hoped that setting a flag between the RCSwitch.available and .resetAvailable calls would do this, but that doesn't work.
Is there a way to ensure only one interrupt is responded to (assuming that the transmitter button is staying down long enough to trigger several)?
Or does anyone know of a simpler library item for listening to the receiver?
#include <RCSwitch.h>
RCSwitch Radio = RCSwitch();
bool demand = false;
void setup() {
Radio.enableReceive(0); //Radio on interrupt 0 => that is pin 2
homeflip();
}
void loop() {
demand = false; //Clear demand
if (Radio.available()) {
demand = true;
Radio.resetAvailable();
}
while (demand) { //Wait for radio demand signal
flip();
homeflip();
demand = false;
}
}
Not with no idea what flip() and homeflip() consist in.
Post a sketch that is complete and say what happens twice.
The examples in the library might be good to look at. Theoretically you shouldn't need to even know that interrupts are involved, that is not where you need to figure out what is going wrong, I don't think.
@jremington No I was not. Does this mean that the switch is happy to take ON ON ON ON to mean ON, for example? I had hoped to avoid getting and interpreting the data sent as it is irrelevent - I just need to know that a remote button has been pressed.
void loop() {
demand = false; //Clear demand
if (Radio.available()) {
demand = true;
// not here right away... Radio.resetAvailable();
}
while (demand) { //Wait for radio demand signal
flip();
homeflip();
// here, so you ignore any that arrived right away or around the one that set you flag
// for all the time that flip/homeFlip took. Seconds:
Radio.resetAvailable();
demand = false;
}
}
Walk your finger through it. You have to reset/cancle the official availability state.
If flip() and homeFlip() do not, as they appear to do, take many milliseconds, try throwing a delay in there long enough for... you to get your finger off the button and the transmitter to finich anything it had in progress.
If the blocking of flip() and homeFlip() or the extra delay I suggest become a problem, there are ways to code it so the net effect is the same but you can have your code juggling chainsaws in the meantime. Or calculating a few more digits of π, whatever.
In general, don't tell anyone you've handled something until you have. Handled it.