IR-library, cant extract code from string

By 'mistake' I bought a couple of "Nibobee" robots. (got totally NOT what I expected)
Thet are based om ATmega16, so I flashed a bootloader .. all good so far.
I found this library for receiving IR codes:

The example (below) shows me the correct result on the serial monitor.. I dont need this, but rather the last two chars from the IR-code itself. I've searched the documentation I can find, but have not found the solution yet.
Help is appreciated..

/*  https://github.com/z3t0/Arduino-IRremote. */
#include <IRremote.h>
#define IR_RECEIVE_PIN  25  // ATMEGA16
IRrecv IrReceiver(IR_RECEIVE_PIN);

byte code ;
void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  IrReceiver.enableIRIn();  // Start the receiver
}
void loop()
{
  if (IrReceiver.decode())  
  {
    IrReceiver.printResultShort(&Serial);
    IrReceiver.resume(); // Enable receiving of the next value
// ********** I need the last two chars from the IR code *** like:
   byte my_code= ??? ; // cannot fins a way to extrackt what I need
// ********************************
  }
}

Is the IR code always the same length ?
What data type is it ?

Please post a complete sketch that illustrates what you want to do and an example of the received IR code and explain what data type you want the extracted data to be in

When I comment out thle line I really want finishes: ( byte my_code= ??? )
I get this printout: (one line for each button om my remote)

Protocol=NEC Address=0x0 Command=0x0 Raw-Data=0x10C8C13E (32 bits)
Protocol=NEC Address=0x0 Command=0x0 Raw-Data=0x10C8817E (32 bits)
Protocol=NEC Address=0x0 Command=0x0 Raw-Data=0x10C841BE (32 bits)
Protocol=NEC Address=0x0 Command=0x0 Raw-Data=0x10C8A15E (32 bits)

I cannot fint enough in the docs on github to complete. I'd really like to get those last two chars stored in a byte.
In the code, theres this link to the github lib.

I looked up the examples of the library you linked to and found something interesting for you inside of this example
https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/IR2Keyboard/IR2Keyboard.ino

best regards Stefan

SOLVED. (finally found some 'missing info' )
Working code: (not perfect yest)

/*  https://github.com/z3t0/Arduino-IRremote. */

#include <IRremote.h>
#define IR_RECEIVE_PIN  25  // ATMEGA16
IRrecv IrReceiver(IR_RECEIVE_PIN);
decode_results results;  // added

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  IrReceiver.enableIRIn();  // Start the receiver
}
void loop()
{
  if (IrReceiver.decode(&results))
  {
    byte code = results.value & 0xFF ;
    Serial.println(code, HEX);
    IrReceiver.resume(); // Enable receiving of the next value
  }
}

Thank for hints, I'm started.

Be aware that results is deprecated in that library. There is a read() method that returns a pointer to an IRData struct which contains the data that you're looking for.

Below the method

/**
 *@return decoded IRData,
 */
IRData* IRrecv::read() {
    if (irparams.rcvstate != IR_REC_STATE_STOP) {
        return NULL;
    }
    if (decode()) {
        return &decodedIRData;
    } else {
        return NULL;
    }
}

Make sure that you check for NULL before using the IRData.

The struct:

struct IRData {
    decode_type_t protocol;     ///< UNKNOWN, NEC, SONY, RC5, ...
    uint16_t address;           ///< Decoded address
    uint16_t command;           ///< Decoded command
#if defined(ENABLE_EXTRA_INFO)
    uint16_t extra;             ///< Used by MagiQuest and for Kaseikyo unknown vendor ID
#endif
    uint8_t numberOfBits;    ///< Number of bits received for data (address + command + parity + etc.) to determine protocol length.
    uint8_t flags;              ///< See definitions above
    uint32_t decodedRawData;    ///< up to 32 bit decoded raw data, formerly used for send functions.
    irparams_struct *rawDataPtr; /// pointer of the raw timing data to be decoded
};

Thanks again. code updated.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.