IR Remote Recognizing Button Held

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.

I am using these 2 products:

https://www.sparkfun.com/products/11759

https://www.sparkfun.com/products/8554

Based on the example here:

http://dlnmh9ip6v2uc.cloudfront.net/dat … xample.ino

I’m not sure what your question is. Does the existing code work in identifying the buttons pressed or not ?

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

http://arduino.cc/en/Tutorial/ButtonStateChange

I hope this helps.

Most remotes send a burst of 3-4 copies of the keycode on first press, then if you hold

the button it transmits a repeat code of all 1’s like 0xFFFFFFFF until release.

The standard IRemote library will give you result.value = 0xFFFFFFFF in most cases,

regardless of the bit length used by the protocol - at least that has been my experience.

The IRecvDemo example will show you the stream of codes it receives so you can

observe what a single press vs. press/hold looks like.

Your sketch needs to remember what was the most recently received non-repeat value,

then when you do see a repeat you can know what button is being held down.

You should also use a small timeout to handle the case when the initial code is

missed and you start to pick up a repeat that is not associated with the most

recent successfully decoded value - also to reject noise which can come in as

all 1’s.

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();
  }
}