Currently if signal is received it goes through switch/case statement to run respective function that is assigned to button. So if you send 2 signals by accident you could run the function twice.
What I thought at first was to make a timeout, like if the button is pressed for longer than 1000 ms, count it as a new input, but that's cumbersome to implement; to check in every loop if the button is still held.
What I want to achieve is no matter how long the button is pressed I only want it to count once. Not sure how to go about that.
What remote do you have? Some don't send the same code many times in a row but rather send a repeat code to say "it is the same as the last one, user did not let go"
As far as I know the repeat code is only for IR, and I'm working on RF. I tested it and it constantly sends the same code not the repeat one. I forgot the chipset but the model is https://m.aliexpress.com/s/item/32725306116.html
ah sorry - read too fast and thought about IR, not RF
how fast do you receive two consecutive code when the button is kept pressed? if that's slow enough for a user to be able to do it with a double click on the button, then it will be impossible to tell if that was 1 long press sending 2 codes or 2 short press in a row.. (unless you go deeper in the library and are able to detect incoming signal being decoded)
Sorry for the late reply, the data frequency seems to be 10 Hz (every 105 millis) at point blank range.
While programming the remote in the library there is
// Optional set pulse length.
// mySwitch.setPulseLength(320);
I'm not sure what I used for programming my remote, I will check what happens if I increase this value. But not today as I don't have any time. Almost all parts came for the project so I will be tinkering with it on the weekend, but I'd like to have the programming side done before that.
For now I will just ignore the inputs if they are the same for 1st sec.
Also I have RF driveway gate that also constantly sends data, and no matter how long you press "open/close" button it works, so there is gotta be a way to do this "right".
Iirc setpulselength was for transmitting signals, not receiving them.
The timeout solution is the common approach. You just have to get creative with some time tracking.
For example, mark time when signal is received. Then disable retrigger until a chosen interval of no signal has passed. In plain terms, you're requiring the button be released before new commands are acknowledged.
When the button is held down, every new signal resets the timer.