NEC sometimes multiple receiving same code

Board: ARDUINO Micro
Library Version: 2.3.3 ( IRremote )
Protocol: NEC

Hello. Im working with NEC protocol on Apple remote control with enabled holding key with "Decoded NEC: FFFFFFFF (0 bits)".

I have conntected 2 arduino (one which are displaying code on serial monitor (arduino uno), second - driver which Im programming (arduino micro).

 if (irrecv.decode(&results))
  {
    if (results.decode_type == NEC)
    {
      currentButtonCode = results.value;
      if (currentButtonCode == 0xFFFFFFFF) {
            currentButtonCode = lastButtonCode;
            blokadaPilot=0;
        } else {
            lastButtonCode = currentButtonCode;
blokadaPilot=1;
        }

  if (results.value== Button3 && count == 0 && mute_pressed==0 && blokadaPilot==1)
      {
        vol = vol + 0.5;
        if (vol > 127)vol = 127;
      }

      else if (currentButtonCode == Button3 && count == 0 && mute_pressed==0 && blokadaPilot==0)
      {
        vol = vol + 5;
        if (vol > 127)vol = 127;
      }

      if (results.value == Button4 && count == 0 && mute_pressed==0 && blokadaPilot==1)
      {
        vol = vol - 0.5;
        if (vol < 0)vol = 0;
      }
 
      else if (currentButtonCode == Button4 && count == 0 && mute_pressed==0 && blokadaPilot==0)
      {
        vol = vol - 5;
        if (vol < 0)vol = 0;
      }
    }
  irrecv.resume();
}

Button3;4 - code from Apple remote, up down key

count - work only when count 0 is set (must be)

mute_pressed - work only, when mute_pressed is 0 (must be)

blokadaPilot=0 - work only, when you holding key (increase/decrease vol by 5) - added because Im looking for solve problem

blokadaPilot=1 - work only, when you are pressing key (increase/decrease vol by 0.5) - added because Im looking for solve problem

unsigned long currentButtonCode;

unsigned long lastButtonCode;

Problem is: sometimes when Im pressing (not holding) up or down key , it should be decrease/increase by 0.5 , but its not. Sometimes its increase/decrease by 0,5+5 or 5. But when Im looking at same time when was increased/decreased wrong (0,5+5 or only 5) in arduino uno, which have Irdump v1 or v2 - it was nothing wrong. So I think that NEC protocol has bug in software/library.

When Im holding key - always is increase/decrease by 5 - so its work ok. I have never seen that it was increase/decrease by 0,5 + 5

When I had disabled function with holding key, only pressing key all works ok, always decrease/increase by 0.5

Why 2 functions - one for 0.5 , second for 5? I would like to increa/decrease when pressing by 0.5, when holding by 5 or 10 But I think that this future have bug?

Thanks and have a good day to all

Could you post enough of you sketch to allow it to compile? The part you included is missing lots of declarations and has no code that would change 'count' or 'mute_pressed'.

Here is a way to use some of the more advanced features of C++ to make the code easier to read:

  if (irrecv.decode(&results))
  {
    boolean isARepeat = false;


    if (results.decode_type == NEC)
    {
      currentButtonCode = results.value;


      if (currentButtonCode == 0xFFFFFFFF)
      {
        currentButtonCode = lastButtonCode;
        isARepeat = true;
      }
      else
      {
        lastButtonCode = currentButtonCode;
        isARepeat = false;
      }


      switch (currentButtonCode)
      {
        case Button3:
          if (isARepeat)
            vol += 5;
          else
            vol += 0.5;
          break;




        case Button4:
          if (isARepeat)
            vol -= 5;
          else
            vol -= 0.5;
          beak;


      }
      vol = constrain(vol, 0, 127);


    }
    irrecv.resume();
  }

Thanks a lot for reply. There is a lot of variables in code, I can post only things which need for compile for IR control.

Anyway, I have changed code for yours and:

final.ino: In function 'void loop()':

final:502:14: error: the value of 'Button3' is not usable in a constant expression

         case Button3:

              ^~~~~~~

final.ino:92:15: note: 'long unsigned int Button3' is not const

 unsigned long Button3 = 0x77E1D04B; //vol up

               ^~~~~~~

final:502:14: error: the value of 'Button3' is not usable in a constant expression

         case Button3:

              ^~~~~~~

final.ino:92:15: note: 'long unsigned int Button3' is not const

 unsigned long Button3 = 0x77E1D04B; //vol up

               ^~~~~~~

final:512:14: error: the value of 'Button4' is not usable in a constant expression

         case Button4:

              ^~~~~~~

final.ino:93:15: note: 'long unsigned int Button4' is not const

 unsigned long Button4 = 0x77E1B04B; //vol down

               ^~~~~~~

final:512:14: error: the value of 'Button4' is not usable in a constant expression

         case Button4:

              ^~~~~~~

final.ino:93:15: note: 'long unsigned int Button4' is not const

 unsigned long Button4 = 0x77E1B04B; //vol down

               ^~~~~~~

exit status 1
the value of 'Button3' is not usable in a constant expression

changed Button3 ; Button4 in cases for code

        case 0x77E1D04B:
          if (isARepeat)
            vol += 5;
          else
            vol += 0.5;
          break;




        case 0x77E1B04B:
          if (isARepeat)
            vol -= 5;
          else
            vol -= 0.5;
          break;

and still same problem. Working ok when holding key (inc/decrease by 5, always) but when clicking - sometimes inc/dec for 0.5 , sometimes for 5 sometimes for 5.5

from original code which I have posted, we can used this:

if (irrecv.decode(&results))
  {
    if (results.decode_type == NEC)
    {
      currentButtonCode = results.value;
      if (currentButtonCode == 0xFFFFFFFF) {
            currentButtonCode = lastButtonCode;
        } else {
            lastButtonCode = currentButtonCode;
        }

  if (results.value== Button3 )
      {
        vol = vol + 0.5;
        if (vol > 127)vol = 127;
      }

      else if (currentButtonCode == Button3)
      {
        vol = vol + 5;
        if (vol > 127)vol = 127;
      }

      if (results.value == Button4)
      {
        vol = vol - 0.5;
        if (vol < 0)vol = 0;
      }
 
      else if (currentButtonCode == Button4)
      {
        vol = vol - 5;
        if (vol < 0)vol = 0;
      }
    }
  irrecv.resume();

and for compile:

#include <IRremote.h>
#define irPin 5 //changed in IRremote library timers for 32u4
IRrecv irrecv(irPin);
decode_results results;

unsigned long Button1 = 0x77E1E04B; //next in
unsigned long Button2 = 0x77E1104B; //prev in
unsigned long Button3 = 0x77E1D04B; //vol up
unsigned long Button4 = 0x77E1B04B; //vol down
unsigned long Button5 = 0x77E1404B; //menu
unsigned long Button6 = 0x77E17A4B; //playpause//mute
unsigned long Button7 = 0x77E1BA4B; //ok

unsigned long currentButtonCode;
unsigned long lastButtonCode;

volatile float vol;

void setup()
{
  irrecv.enableIRIn();


  vol = 30; //starts volume
}

void loop()
{
if (irrecv.decode(&results))
  {
    if (results.decode_type == NEC)
    {
      currentButtonCode = results.value;
      if (currentButtonCode == 0xFFFFFFFF) {
            currentButtonCode = lastButtonCode;
        } else {
            lastButtonCode = currentButtonCode;
        }

  if (results.value== Button3 )
      {
        vol = vol + 0.5;
        if (vol > 127)vol = 127;
      }

      else if (currentButtonCode == Button3)
      {
        vol = vol + 5;
        if (vol > 127)vol = 127;
      }

      if (results.value == Button4)
      {
        vol = vol - 0.5;
        if (vol < 0)vol = 0;
      }
 
      else if (currentButtonCode == Button4)
      {
        vol = vol - 5;
        if (vol < 0)vol = 0;
      }
    }
  irrecv.resume();
}

I wrote a sketch to test your input processing logic and I can't replicate the problem you are reporting. I think you may have to show more of your code in order for us to help further.

const unsigned long RepeatCode = 0xFFFFFFFF;


const unsigned long Button1 = 0x77E1E04B; //next in
const unsigned long Button2 = 0x77E1104B; //prev in
const unsigned long Button3 = 0x77E1D04B; //vol up
const unsigned long Button4 = 0x77E1B04B; //vol down
const unsigned long Button5 = 0x77E1404B; //menu
const unsigned long Button6 = 0x77E17A4B; //playpause//mute
const unsigned long Button7 = 0x77E1BA4B; //ok


unsigned long currentButtonCode;
unsigned long lastButtonCode;


void setup()
{
  Serial.begin(115200);


  processInput(Button3);
  processInput(RepeatCode);
  processInput(Button4);
  processInput(RepeatCode);
  processInput(Button3);
  processInput(Button3);
  processInput(RepeatCode);
  processInput(Button4);
  processInput(Button4);
  processInput(RepeatCode);
  processInput(Button3);
  processInput(Button4);
  processInput(RepeatCode);
  processInput(Button4);
  processInput(Button3);
  processInput(RepeatCode);
}


void processInput(unsigned long RV)
{
  currentButtonCode = RV;
  if (currentButtonCode == RepeatCode)
  {
    currentButtonCode = lastButtonCode;
  }
  else
  {
    lastButtonCode = currentButtonCode;
  }


  Serial.print(name(RV));
  Serial.print('\t');
  Serial.print(name(currentButtonCode));
  Serial.print('\t');
  Serial.println(name(lastButtonCode));


  if (RV == Button3)
  {
    Serial.println("Up 0.5");
  }
  else if (currentButtonCode == Button3)
  {
    Serial.println("Up 5");
  }


  if (RV == Button4)
  {
    Serial.println("Down 0.5");
  }
  else if (currentButtonCode == Button4)
  {
    Serial.println("Down 5");
  }


}


const char *name(const unsigned long val)
{
  switch (val)
  {
    case Button3: return "Button3";
    case Button4: return "Button4";
    case RepeatCode: return "Repeat";
  }
  return "Unknown";
}


void loop() {}

Results are:

Button3	Button3	Button3
Up 0.5
Repeat	Button3	Button3
Up 5
Button4	Button4	Button4
Down 0.5
Repeat	Button4	Button4
Down 5
Button3	Button3	Button3
Up 0.5
Button3	Button3	Button3
Up 0.5
Repeat	Button3	Button3
Up 5
Button4	Button4	Button4
Down 0.5
Button4	Button4	Button4
Down 0.5
Repeat	Button4	Button4
Down 5
Button3	Button3	Button3
Up 0.5
Button4	Button4	Button4
Down 0.5
Repeat	Button4	Button4
Down 5
Button4	Button4	Button4
Down 0.5
Button3	Button3	Button3
Up 0.5
Repeat	Button3	Button3
Up 5

I think that its not problem with sketch, I think that main problem is in IRremote / Apple remote controler. Sometimes its sends wrong code/"ghost" code and IRremote library is bugging.

#include "IRremote.h"
#include "IRremoteInt.h"

//==============================================================================
//                           N   N  EEEEE   CCCC
//                           NN  N  E      C
//                           N N N  EEE    C
//                           N  NN  E      C
//                           N   N  EEEEE   CCCC
//==============================================================================

#define NEC_BITS          32
#define NEC_HDR_MARK    9000
#define NEC_HDR_SPACE   4500
#define NEC_BIT_MARK     560
#define NEC_ONE_SPACE   1690
#define NEC_ZERO_SPACE   560
#define NEC_RPT_SPACE   2250

//+=============================================================================
#if SEND_NEC
void  IRsend::sendNEC (unsigned long data,  int nbits)
{
 // Set IR carrier frequency
 enableIROut(38);

 // Header
 mark(NEC_HDR_MARK);
 space(NEC_HDR_SPACE);

 // Data
 for (unsigned long  mask = 1UL << (nbits - 1);  mask;  mask >>= 1) {
 if (data & mask) {
 mark(NEC_BIT_MARK);
 space(NEC_ONE_SPACE);
 } else {
 mark(NEC_BIT_MARK);
 space(NEC_ZERO_SPACE);
 }
 }

 // Footer
 mark(NEC_BIT_MARK);
 space(0);  // Always end with the LED off
}
#endif

//+=============================================================================
// NECs have a repeat only 4 items long
//
#if DECODE_NEC
bool  IRrecv::decodeNEC (decode_results *results)
{
 long  data   = 0;  // We decode in to here; Start with nothing
 int   offset = 1;  // Index in to results; Skip first entry!?

 // Check header "mark"
 if (!MATCH_MARK(results->rawbuf[offset], NEC_HDR_MARK))  return false ;
 offset++;

 // Check for repeat
 if ( (irparams.rawlen == 4)
    && MATCH_SPACE(results->rawbuf[offset  ], NEC_RPT_SPACE)
    && MATCH_MARK (results->rawbuf[offset+1], NEC_BIT_MARK )
   ) {
 results->bits        = 0;
 results->value       = REPEAT;
 results->decode_type = NEC;
 return true;
 }

 // Check we have enough data
 if (irparams.rawlen < (2 * NEC_BITS) + 4)  return false ;

 // Check header "space"
 if (!MATCH_SPACE(results->rawbuf[offset], NEC_HDR_SPACE))  return false ;
 offset++;

 // Build the data
 for (int i = 0;  i < NEC_BITS;  i++) {
 // Check data "mark"
 if (!MATCH_MARK(results->rawbuf[offset], NEC_BIT_MARK))  return false ;
 offset++;
        // Suppend this bit
 if      (MATCH_SPACE(results->rawbuf[offset], NEC_ONE_SPACE ))  data = (data << 1) | 1 ;
 else if (MATCH_SPACE(results->rawbuf[offset], NEC_ZERO_SPACE))  data = (data << 1) | 0 ;
 else                                                            return false ;
 offset++;
 }

 // Success
 results->bits        = NEC_BITS;
 results->value       = data;
 results->decode_type = NEC;

 return true;
}
#endif

maybe its possible to add delay/space between next code?

Serial monitor:
it was only clicking, not holding key. And as all can see - sketch read in one moment as holding key. I dont know its something wrong with Apple remote control or IRremote library. But to solve this problem I think that I need delay/space beetween each pressing key.

lastButtonCode
2011287627
isARepeat
0
lastButtonCode
2011287627
isARepeat
0
lastButtonCode
2011287627
isARepeat
0
lastButtonCode
2011287627
isARepeat
0
lastButtonCode
2011287627
isARepeat
1

Play/pause key on Apple remote, always send good code and 0xFFFF, but IRremote control on arduino uno with IRdump cant see second wrong code. (sometimes other buttons send good code and 0xFFF too)

Only pressing/clicking one time:

12:54:29.317 -> lastButtonCode
12:54:29.317 -> 2011265611
12:54:29.317 -> isARepeat
12:54:29.317 -> 0
12:54:29.420 -> lastButtonCode
12:54:29.420 -> 2011242571
12:54:29.420 -> isARepeat
12:54:29.420 -> 0
12:54:29.350 -> 77E17A4B
12:54:29.350 -> Decoded NEC: 77E17A4B (32 bits)
12:54:29.384 -> Raw (68): 9050 -4400 650 -450 650 -1600 650 -1550 600 -1600 650 -500 650 -1550 650 -1600 600 -1600 600 -1600 650 -1600 600 -1600 600 -500 650 -500 650 -450 600 -550 600 -1600 650 -450 650 -1600 650 -1550 650 -1550 650 -1600 600 -500 600 -1650 600 -500 600 -500 650 -1600 600 -500 600 -500 650 -1600 650 -450 600 -1600 650 -1600 650

(2011242571 its 0xFFFF)

holding:

12:56:12.963 -> lastButtonCode
12:56:12.963 -> 2011265611
12:56:12.963 -> isARepeat
12:56:12.963 -> 0
12:56:13.067 -> lastButtonCode
12:56:13.067 -> 2011242571
12:56:13.067 -> isARepeat
12:56:13.067 -> 0
12:56:13.136 -> lastButtonCode
12:56:13.136 -> 2011242571
12:56:13.136 -> isARepeat
12:56:13.136 -> 1
12:56:13.239 -> lastButtonCode
12:56:13.239 -> 2011242571
12:56:13.239 -> isARepeat
12:56:13.239 -> 1
12:56:13.342 -> lastButtonCode
12:56:13.342 -> 2011242571
12:56:13.342 -> isARepeat
12:56:13.342 -> 1
12:56:13.445 -> lastButtonCode
12:56:13.445 -> 2011242571
12:56:13.445 -> isARepeat
12:56:13.445 -> 1
12:56:13.546 -> lastButtonCode
12:56:13.546 -> 2011242571
12:56:13.546 -> isARepeat
12:56:13.546 -> 1
12:56:13.648 -> lastButtonCode
12:56:13.648 -> 2011242571
12:56:13.648 -> isARepeat
12:56:13.648 -> 1
12:56:13.751 -> lastButtonCode
12:56:13.751 -> 2011242571
12:56:13.751 -> isARepeat
12:56:13.751 -> 1
12:56:13.854 -> lastButtonCode
12:56:13.854 -> 2011242571
12:56:13.854 -> isARepeat
12:56:13.854 -> 1
12:56:12.980 -> 77E17A4B
12:56:12.980 -> Decoded NEC: 77E17A4B (32 bits)
12:56:13.015 -> Raw (68): 9050 -4400 600 -500 600 -1600 600 -1600 650 -1600 600 -500 600 -1600 600 -1600 650 -1600 600 -1600 600 -1600 600 -1600 600 -550 600 -500 650 -450 600 -500 650 -1600 600 -500 600 -1600 650 -1550 650 -1600 600 -1600 650 -450 600 -1600 650 -500 600 -500 600 -1600 600 -500 650 -500 650 -1550 600 -500 650 -1600 600 -1600 600 
12:56:13.360 -> FFFFFFFF
12:56:13.395 -> Decoded NEC: FFFFFFFF (0 bits)
12:56:13.395 -> Raw (4): 9050 -2200 650 
12:56:13.463 -> FFFFFFFF
12:56:13.463 -> Decoded NEC: FFFFFFFF (0 bits)
12:56:13.498 -> Raw (4): 9050 -2200 600 
12:56:13.567 -> FFFFFFFF
12:56:13.567 -> Decoded NEC: FFFFFFFF (0 bits)
12:56:13.601 -> Raw (4): 9050 -2200 600 
12:56:13.669 -> FFFFFFFF
12:56:13.669 -> Decoded NEC: FFFFFFFF (0 bits)
12:56:13.704 -> Raw (4): 9050 -2150 650 
12:56:13.774 -> FFFFFFFF
12:56:13.774 -> Decoded NEC: FFFFFFFF (0 bits)
12:56:13.808 -> Raw (4): 9100 -2150 600 
12:56:13.911 -> FFFFFFFF
12:56:13.911 -> Decoded NEC: FFFFFFFF (0 bits)
12:56:13.945 -> Raw (4): 9050 -2200 650

**again, just clicking and without 0xFFF value of isArepeat change to 1**

12:58:07.284 -> lastButtonCode
12:58:07.284 -> 2011238475
12:58:07.284 -> isARepeat
12:58:07.284 -> 0
12:58:07.353 -> lastButtonCode
12:58:07.353 -> 2011238475
12:58:07.353 -> isARepeat
12:58:07.353 -> 1
12:58:08.381 -> lastButtonCode
12:58:08.381 -> 2011238475
12:58:08.381 -> isARepeat
12:58:08.381 -> 0
12:58:08.416 -> lastButtonCode
12:58:08.416 -> 2011238475
12:58:08.416 -> isARepeat
12:58:08.416 -> 1
12:58:09.514 -> lastButtonCode
12:58:09.514 -> 2011238475
12:58:09.514 -> isARepeat
12:58:09.514 -> 0
12:58:09.549 -> lastButtonCode
12:58:09.549 -> 2011238475
12:58:09.549 -> isARepeat
12:58:09.549 -> 1
12:58:19.493 -> lastButtonCode
12:58:19.493 -> 2011238475
12:58:19.493 -> isARepeat
12:58:19.493 -> 0
12:58:19.528 -> lastButtonCode
12:58:19.528 -> 2011238475
12:58:19.528 -> isARepeat
12:58:19.528 -> 1
12:58:20.664 -> lastButtonCode
12:58:20.664 -> 2011238475
12:58:20.664 -> isARepeat
12:58:20.664 -> 0
12:58:21.972 -> lastButtonCode
12:58:21.972 -> 2011238475
12:58:21.972 -> isARepeat
12:58:21.972 -> 0
12:58:22.005 -> lastButtonCode
12:58:22.005 -> 2011238475
12:58:22.005 -> isARepeat
12:58:22.005 -> 1
12:58:23.031 -> lastButtonCode
12:58:23.031 -> 2011238475
12:58:23.031 -> isARepeat
12:58:23.031 -> 0
12:58:24.432 -> lastButtonCode
12:58:24.432 -> 2011238475
12:58:24.432 -> isARepeat
12:58:24.432 -> 0
12:58:24.467 -> lastButtonCode
12:58:24.467 -> 2011238475
12:58:24.467 -> isARepeat
12:58:24.467 -> 1


12:58:07.289 -> Decoded NEC: 77E1104B (32 bits)
12:58:07.324 -> Raw (68): 9050 -4400 600 -550 600 -1600 600 -1650 550 -1650 600 -500 600 -1650 600 -1600 600 -1650 550 -1650 600 -1600 600 -1650 550 -550 600 -500 600 -550 600 -500 600 -1650 550 -550 600 -550 550 -550 600 -1600 600 -550 600 -500 600 -550 550 -550 600 -500 600 -1650 600 -500 600 -550 550 -1650 600 -500 600 -1650 600 -1600 600
12:58:08.388 -> 77E1104B
12:58:08.388 -> Decoded NEC: 77E1104B (32 bits)
12:58:08.422 -> Raw (68): 9050 -4450 550 -550 600 -1600 600 -1650 600 -1600 600 -550 550 -1650 600 -1600 600 -1650 550 -1650 600 -1650 550 -1650 600 -500 600 -550 600 -500 600 -550 550 -1650 600 -500 600 -550 600 -500 600 -1650 550 -550 600 -550 550 -550 600 -500 600 -550 550 -1650 600 -550 550 -550 600 -1600 600 -550 550 -1650 600 -1650 600
12:58:09.527 -> 77E1104B
12:58:09.527 -> Decoded NEC: 77E1104B (32 bits)
12:58:09.562 -> Raw (68): 9050 -4450 600 -500 600 -1650 550 -1650 600 -1600 600 -550 600 -1600 600 -1650 550 -1650 600 -1600 600 -1650 600 -1600 600 -550 550 -550 600 -500 600 -550 600 -1600 600 -550 550 -550 600 -500 600 -1650 600 -500 600 -550 550 -550 600 -500 600 -550 600 -1600 600 -550 550 -550 600 -1600 600 -550 600 -1600 600 -1650 600
12:58:19.506 -> 77E1104B
12:58:19.506 -> Decoded NEC: 77E1104B (32 bits)
12:58:19.540 -> Raw (68): 9050 -4400 600 -500 600 -1650 550 -1650 550 -1650 600 -500 600 -1650 550 -1650 550 -1650 600 -1600 600 -1600 600 -1600 600 -550 600 -500 600 -500 600 -550 550 -1650 600 -500 600 -550 550 -550 600 -1600 600 -500 600 -550 600 -500 600 -500 600 -550 550 -1650 600 -500 600 -500 600 -1650 550 -550 600 -1600 600 -1650 550
12:58:20.676 -> 77E1104B
12:58:20.676 -> Decoded NEC: 77E1104B (32 bits)
12:58:20.709 -> Raw (68): 9000 -4450 550 -550 600 -1600 600 -1600 600 -1650 550 -550 600 -1600 600 -1600 600 -1650 550 -1650 600 -1600 600 -1600 600 -550 550 -550 600 -500 600 -550 550 -1650 600 -500 600 -500 600 -550 600 -1600 600 -500 600 -550 550 -550 600 -500 600 -550 550 -1650 550 -550 600 -500 600 -1650 550 -550 600 -1600 600 -1650 550
12:58:21.978 -> 77E1104B
12:58:21.978 -> Decoded NEC: 77E1104B (32 bits)
12:58:22.013 -> Raw (68): 9000 -4400 600 -500 600 -1650 550 -1650 600 -1600 600 -550 550 -1650 550 -1650 600 -1600 600 -1600 600 -1650 550 -1650 600 -500 600 -550 550 -550 600 -500 600 -1650 550 -550 600 -500 600 -550 550 -1650 600 -500 600 -500 600 -550 600 -500 600 -500 600 -1650 550 -550 600 -500 600 -1650 550 -550 600 -1600 600 -1650 550
12:58:23.070 -> 77E1104B
12:58:23.070 -> Decoded NEC: 77E1104B (32 bits)
12:58:23.105 -> Raw (68): 9050 -4450 550 -550 600 -1600 600 -1650 600 -1600 600 -550 550 -1650 600 -1600 600 -1650 600 -1600 600 -1650 550 -1650 600 -500 600 -550 600 -500 600 -550 550 -1650 600 -500 600 -550 600 -500 600 -1650 550 -550 600 -500 600 -550 600 -500 600 -550 550 -1650 600 -500 600 -550 600 -1600 600 -550 550 -1650 600 -1650 550
12:58:24.446 -> 77E1104B
12:58:24.446 -> Decoded NEC: 77E1104B (32 bits)
12:58:24.481 -> Raw (68): 9100 -4400 600 -550 600 -1600 600 -1600 600 -1650 600 -500 600 -1650 550 -1650 600 -1600 600 -1650 600 -1600 600 -1650 550 -550 600 -500 600 -550 600 -500 600 -1650 550 -550 600 -500 600 -550 600 -1600 600 -550 550 -550 600 -500 600 -550 600 -500 600 -1650 550 -550 600 -500 600 -1650 600 -500 600 -1650 550 -1650 600

IR:

if (irrecv.decode(&results))
  {
    boolean isARepeat = false;


    if (results.decode_type == NEC)
    {
      currentButtonCode = results.value;


      if (currentButtonCode == 0xFFFFFFFF)
      {
        currentButtonCode = lastButtonCode;
        isARepeat = true;
      }
      else
      {
        lastButtonCode = currentButtonCode;
        isARepeat = false;
      }


      switch (currentButtonCode)
      {
        case 0x77E1D04B:
          if (isARepeat)
            vol += 5;
          else
            vol += 0.5;
          break;




        case 0x77E1B04B:
          if (isARepeat)
            vol -= 5;
          else
            vol -= 0.5;
          break;


      }
      vol = constrain(vol, 0, 127);


    }
 Serial.println("lastButtonCode");
Serial.println(currentButtonCode);
Serial.println("isARepeat");
Serial.println(isARepeat);   
  
  irrecv.resume();
  delay(10); //with or without same situation
}

With delay 30-50ms work perfect. But maybe it would be better change delay to millis?

Hello. Now Im working with storing codes in eeprom. But I have some troubles.

#include <IRremote.h>
#define irPin 5
IRrecv irrecv(irPin);
decode_results results;

#include <EEPROM.h>

unsigned long Button1 = 0; //next in // prawo

#define menuVol A0


void setup()
{
  irrecv.enableIRIn();
  Serial.begin(9600);
  pinMode(menuVol, INPUT);
}


void loop()
{
  if (irrecv.decode(&results))
  {
    if (results.decode_type == NEC)
    {
      Serial.println("button1 read");
      Serial.println(results.value, HEX);
      Button1 = results.value;
      EEPROM.update(0, Button1);
      delay(50);
    }
    irrecv.resume(); // Continue receiving
  }

  if (digitalRead(menuVol) == HIGH)
  {
    Button1 = EEPROM.read(0);
    delay(100);
    Serial.println("button 1 power reset");
    Serial.println(Button1, HEX);
  }
}

with this I have only last 2 digits.

button1 read
77E1BA4B
button 1 power reset
4B

button1 read
77E1C010
button 1 power reset
10

same situation when im not using update, but "put".

Replied in DM.

Use EEPROM.put() and EEPROM.get() for anything larger than one byte.