Trying to get IR library to work

BITD I wrote quite a few sketches using old tv remotes, checking the outputs from them and writing programs to receive signals from them and trigger outputs.

I have tried to get back to it with the up to date version of the irremote library but kept getting the offer to load the IR library 2.6.0 which I finally have done. I can now receive signals using irrecvDemo.ino from the examples.

/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

#if defined(ESP32)
int IR_RECEIVE_PIN = 15;
#else
int IR_RECEIVE_PIN = 5;
#endif
IRrecv irrecv(IR_RECEIVE_PIN);

decode_results results;

// On the Zero and others we switch explicitly to SerialUSB
#if defined(ARDUINO_ARCH_SAMD)
#define Serial SerialUSB
#endif

void setup() {
    pinMode(LED_BUILTIN, OUTPUT);

    Serial.begin(115200);
#if defined(__AVR_ATmega32U4__)
    while (!Serial)
        ; //delay for Leonardo, but this loops forever for Maple Serial
#endif
#if defined(SERIAL_USB) || defined(SERIAL_PORT_USBVIRTUAL)
    delay(2000); // To be able to connect Serial monitor after reset and before first printout
#endif
    // Just to know which program is running on my Arduino
    Serial.println(F("START " __FILE__ " from " __DATE__));

    // In case the interrupt driver crashes on setup, give a clue
    // to the user what's going on.
    Serial.println("Enabling IRin");
    irrecv.enableIRIn(); // Start the receiver

    Serial.print(F("Ready to receive IR signals at pin "));
    Serial.println(IR_RECEIVE_PIN);
}

void loop() {
    if (irrecv.decode(&results)) 
    {
        Serial.println(results.value, HEX);
        irrecv.resume(); // Receive the next value
    }
    if ((irrecv.decode(&results) == 4FB9867))
    {
        Serial.println("well done")
    }
    delay(100);
}

running it I get a number 4FB9867 when I press a key on my remote so I have added a few lines to try to add a new ‘if’ command that just gives me an indication if it sees the button pressed but I can’t find the correct format for the command.

Am I in the right area and can you tell me what the correct command is or am I unable to read the incoming button press in this way?

Try if (results.value == 0x4FB9867) (note the 0x at the start of the hex constant).

Edit: actually, maybe something more like

    if (irrecv.decode(&results)) 
    {
        Serial.println(results.value, HEX);
        if (results.value == 0x4FB9867))
        {
            Serial.println("well done")
        }
        irrecv.resume(); // Receive the next value
    }
    delay(100);

thank you for the quick reply.

I have been trying all evening and continued to try after I posted this.

I finally got it to work just now. I added the lines shown

 if (irrecv.decode(&results)) 
    {
        Serial.println(results.value, HEX);
        a = (results.value);
        Serial.println (a);
        irrecv.resume(); // Receive the next value
    }
    if (a == -26521)
    {
        Serial.println("well done");
        a=0;
    }
    delay(100);

I read the results.value into a int and got a different number that I used.

I will look at your suggestion of reading it as 0x4FB9867 and see if that also works.

Again thank you for the swift reply.

Putting an unsigned long value into an int variable will have that affect.