I’m trying to give different functions to each IR remote button with single press and held down.
I understand that there’s a repeat signal sent when a button is held but I’m not quite sure how to handle these signals. Any help would be appreciated.
At first thought, I think you could simply set a coded threshold so say a value = up so many times in a row, do something. You can then figure out how many times a command it repeated if you press the button for so long. Make that your threshold, and have your code operate a different function based off that new button function.
A good code to sample for the structure and coding of this I would look over
OK if you’re trying to distinguish btw the “normal” codes and the one for repeat and then make something different happen when A is pressed vs when A is held pressed and thus ‘repeated’ …
I would add a new variable, let’s call it prevResults, and set prevResults = results.value whenever results.value is a recognized value (and not = the repeat code). Then when the repeat code is recognized, that plus the knowledge of the code pressed prior to the repeat (whatever prevResults is), could be coded to send a new msg … like “A repeated” or whatever else you desire.
Add the repeat code (found in the comments section of the IR remote) to the list of defines …
#define POWER 0x10EFD827
#define A 0x10EFF807
#define B 0x10EF7887
#define C 0x10EF58A7
#define UP 0x10EFA05F
#define DOWN 0x10EF00FF
#define LEFT 0x10EF10EF
#define RIGHT 0x10EF807F
#define SELECT 0x10EF20DF
#define REPEAT 0x????????
then set prevResults wherever another cmd is recognized (examples shown below)
void loop()
{
if (irrecv.decode(&results))
{
if (results.value == POWER)
{
Serial.println("POWER");
prevResults = 0x10EFD827;
}
if (results.value == A)
{
Serial.println("A");
prevResults = 0x10EFF807;
}
...
and then add new code to do what you want given the REPEAT code and prevResults …
if (results.value == SELECT)
{
Serial.println("SELECT");
prevResults = 0x10EF20DF;
}
if (results.value == REPEAT)
{
Serial.println("REPEAT");
new code goes here;
}
irrecv.resume();
}
}