Help with IR remote and HEX

See the bottom of this code. I want to setup a case statmente to return the HEX code of a button press but I can't get passed this simple thing. All I can seem to return is an int of 16. I'm not sure how to declare the variable

//include librarys
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>

//defines
const int RECV_PIN = 4;
int MODE = 1;

// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;


// Define LCD pinout
const int  en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3;

// Define I2C Address - change if reqiuired
const int i2c_addr = 0x27;

LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  lcd.begin(16, 2);
  lcd.print("LCD Remote Test");
  irrecv.enableIRIn();
}

void loop() {
  String k = getCode(); // k now contains 6
  //Serial.println(k);
  //delay(500);
}

String getCode() {
  if (irrecv.decode(&results)){
    int test = (results.value, HEX); // this is declared wrong
    Serial.println(test); // who to get to print in HEX??
  }
  switch(MODE){
    
  }
}

.

int test = (results.value, HEX); // this is declared wrong

Not int. unsigned long or uint32_t.

KrafterHD:
See the bottom of this code. I want to setup a case statmente to return the HEX code of a button press but I can't get passed this simple thing. All I can seem to return is an int of 16. I'm not sure how to declare the variable

//include librarys

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>

//defines
const int RECV_PIN = 4;
int MODE = 1;

// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;

// Define LCD pinout
const int  en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3;

// Define I2C Address - change if reqiuired
const int i2c_addr = 0x27;

LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  lcd.begin(16, 2);
  lcd.print("LCD Remote Test");
  irrecv.enableIRIn();
}

void loop() {
  String k = getCode(); // k now contains 6
  //Serial.println(k);
  //delay(500);
}

String getCode() {
  if (irrecv.decode(&results)){
    Serial.println(results.value, HEX); // who to get to print in HEX??
  } else {
    results.value = 0;
  }
  // this is straight out of the String class documentation...
  String thisString = String(results.value, HEX);
  return thisString;
}


.
    unsigned long test = results.value;
    Serial.println(test, HEX);

I can't seem to get any of these suggestions to work. This is an example of the IR receiver. All I wan't to do is return the HEX code from a function but I'm struggling with that for some reason.

/*
 * 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>

int RECV_PIN = 4;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  // 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.println("Enabled IRin");
}

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

Using blh64 example just returned a bunch of gibberish. I've googled this and all I can seem to find are examples on printing out the code or examples with receiving the code on the main loop.

Gibberish? Like when Serial Monitor is not set to the same baud rate that you set in Serial.begin()?

Gibberish? Like when Serial Monitor is not set to the same baud rate that you set in Serial.begin()?

Gibberish like that but not that. Baud rate was correct.

Here's an idea... Post your "gibberish" results so we can see what you are seeing...

Will do this afternoon when I get in.

Your getCode() function does not return anything.

Add below as the last line of the getCode() function.

return String(results.value));

And next learn that it's a bad idea to use Sting (capital S) on microcontrollers that don't have proper memory management.

sterretje:
Your getCode() function does not return anything.

Add below as the last line of the getCode() function.

return String(results.value));

And next learn that it's a bad idea to use Sting (capital S) on microcontrollers that don't have proper memory management.

Ya I know lol. That's why I removed my post. I've did a few things since the OP and had to start over. I obviously got in a hurry and posted to soon.

KrafterHD:
That's why I removed my post.

Was wondering why.

sterretje:
And next learn that it's a bad idea to use Sting (capital S) on microcontrollers that don't have proper memory management.

Well....... Obviously it is a bad idea. Using a string was the issue. I modified the code as follows and it works as I want. Thank you for the advice. Lesson learned lol.

#include <IRremote.h>

int RECV_PIN = 4;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  // 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.println("Enabled IRin");
}

void loop() {
  if (irrecv.decode(&results)) {
    uint32_t k = uint32_t(getCode());
    Serial.println(k, HEX);
  }
}

uint32_t getCode() {
  if (irrecv.decode(&results)) {
    //Serial.println(results.value);
    irrecv.resume(); // Receive the next value
    return uint32_t(results.value);
  }
  delay(100);
}

I don't think that the use of Sting was the cause of your problem in this case.

You now have a few redundant casts.

uint32_t k = uint32_t(getCode());

getCode already returns an uint32_t; so no need to cast (or wahtever your statement exactly does).

return uint32_t(results.value);

results.value is already an uint32_t; so no need to cast (or wahtever your statement exactly does).

Further a cast is normally done with

return (uint32_t)results.value;

Note where the (and ) are. The compiler does not throw warnings, so I have no idea what the compiler did