Convert Int to long or other that can hold a HEX (IR Decoding)

good afternoon to all of you who is giving there time to look at my post :slight_smile:

im trying to decode my Tv remotes in my house but i ran in to some problems :frowning:

#include <IRremote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

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

i used this code to get my Readings from my remotes and got
(C5E8) and (FFFFFFFF) after and when i hold down

now my problem is when i want to send this signal out with my LED (IR) and try to upload the program i get an error

#include <IRremote.h>

int IRpin = 11;  // pin for the IR sensor
int LED = 13;    // LED pin  
IRrecv irrecv(IRpin);
decode_results results;

boolean LEDon = true; // initializing LEDon as true

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(LED, OUTPUT);
}

void loop() 
{
   
  if (irrecv.decode(&results)) 
    {
      
      irrecv.resume();   // Receive the next value
    }
  
  
  
  switch(results.value)
 {

  case C5E8:
  Serial.print("OFF");
  break;
  
  case 02:
  // do another thing
  break;
  
  case 03:
  // feed my dog for me
  break;
  
  default:
  digitalWrite(LED, HIGH);
  
  }
  
}

The error i get is

Arduino: 1.6.3 (Windows 8.1), Board: "Arduino Mega or Mega 2560, ATmega1280"

sketch_apr30a.ino:31:8: error: invalid suffix "Arduino: 1.6.3 (Windows 8.1), Board: "Arduino Mega or Mega 2560, ATmega1280"

sketch_apr30a.ino:31:8: error: invalid suffix "C750AF" on integer constant

Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
" on integer constant

Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

now i do not know alot of code but i do know that a Hex can not be in a (int) so is there a way for me to force to read the Hex code and still be able to send it out to the LED (IR) without any problem and will love if i can keep my Case option :slight_smile:

have a good day

Clipcomet

What type is decode_results ?

Everything in computers is a binary number. Everything. Your statement that "a hex cannot be in an int" is wrong and meaningless.

First, you need to determine what is coming from your remote. And then, you need to send the same thing to the TV, if it is your intention that the arduino does the same thing as the remote does.

You remote is probably sending a number representing a number, although it might be sending a number representing a character representation of something. I can't tell from the code you posted.

If you are assuming it is a number, then the way you represent a large integer as a hexadecimal constant is the notation 0xC750AF where the 0x prefix informs the compiler that the following characters in the source code file represent an integer expressed in hexadecimal format.

  if (irrecv.decode(&results)) 
    {
      
      irrecv.resume();   // Receive the next value
    }
  
  
  
  switch(results.value)

If you get a new value, reset to get the next value. Then, regardless of whether you got a new value, or not, do something with the value that you got last time.

Is that REALLY what you want to do?

Send the Feed The Dog code, and your poor dog will explode from over-eating before you get around to sending another code.

hehe i understand that i know even less then i think ;)

michinyon

many thx for your responds i think i know what do

switch(results.value)
 {

  case 0xC750AF:
  Serial.print("OFF");
  break;
  
  case 02:
  // do another thing
  break;
  
  case 03:
  // feed my dog for me
  break;
  
  default:
  digitalWrite(LED, HIGH);
  
  }

i hope i understand and did not waist your time

PaulS

No i really dont want my dog to die :P

how will you add in the reset? under each Case?

how will you add in the reset? under each Case?

Put the whole switch statement INSIDE the if(irrecv.decode(&results)) block.

So that it becomes "If I got a value and the value is "Feed the mutt", feed the dog".