Ken Shirriff's IRRemote Library is driving me crazy!

Hello all,
I have been using Ken SHirrif's IRREmote library to make a universal remote controller. However there is a MAJOR problem with sending a signal after receiving it from the oroginal device of let's say, a TV!

Now when I receive, I have the decoded IR value as a HEX code (for example: 10EF58A7). However, to send it via IR.sendNEC(long unsigned data, int bits), it has to be written as 0x10EF58A7.

The problem is not in writing that, the problem is that it MUST be a smart code! Meaning that I need to save this ox10EF58A7 in some variable and I am facing hell doing that!

  1. When I change 10EF58A7 to unsigned long, it gives me an int value WHICH DOES NOT MAKE MY TV TURN ON/OFF
  2. When I send 10EF58A7 as it is without the "0x" it is refused because of its mismatching type

P.S My remote DOES work manually (when I type the desired signal after adding 0x to its value in the IR.sendNEC) but the problem is again, automating this process (meaning taking a value from the receiving and sending it after storing it correctly)

Here's my code and please check the comments in it to understand where the problem lies exactly:

/*
 * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
 * An IR LED must be connected to Arduino PWM pin 3.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>
IRsend irsend;

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long value;

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

}

void loop() {
         if (Serial.read() == '0') {
         Serial.println("Transmitting");
         for (int i = 0; i < 3; i++) {
            irsend.sendNEC(value,38); //THE PROBLEM LIES IN VALUE!!!
            delay(40);
         }
         }else if (Serial.read() == '1') {
               if (irrecv.decode(&results)) {
                   Serial.println("Receiving");
                   Serial.println(results.value, HEX);
                   value = results.value; //TRIED value = (long unsigned)(results.value) AND I ALSO TRIED value = (results.value,HEX)!!!

      irrecv.resume(); 
         }
       
  }
}

Where are you setting "value" to the hex code?
Why not try:

  irsend.sendNEC(0x10EF58A7,38);

or

   value=0x10EF58A7;
   irsend.sendNEC(value,38);

I dont want to write the value manually as I want the remote to read and send automatically.
Thats why the value takes its value from results.value which is 10EF58A7.
Now all I want to do is to add 0x before that value and send through sendNEC but I cant choose a proper variable type for value!

PS. when I declare my variable to be:
long unsigned value = 0x10EF58A7

and print it just to be sure it stays the same before I send it in the sendNEC function, it converts this value into a long decimal int! I want it to stay as it is (i.e 0x10EF58A7) so what type should I store value in?! Tough riddle huh? :smiley:

How you print out a variable has nothing to do with how it is actually stored, which is always binary.
There is no such thing as a "long decimal int"; decimal is just one possible interpretation of a long int.

yea i guess i said it in a wrong way :smiley: i meant it coverts it into a decimal number
REgarding the printing, okay lets assume that printing has nothing to do with the way im storing a value...then how can i get my remote to work? :S
all i know is that it works when the value inside the sendNEC function is sth in the form of 0x...other than that it doesnt..so how can i make sure the variable im storing my value in gives that format without inserting it manually but from my receiving signal as explained above?

I don't understand what your problem is. You have a variable called value that you never assign a value to. There is a member in the struct that results is an instance of, called value. You print that, apparently successfully, and then try to send the value in the variable called value, WITHOUT assigning the variable a value.

My recommendation is to NOT use value as the name of a variable.

hmmm i'll change that name okay thanks..
my problem very briefly is this:
I have a function that takes as an input a number of the form 0 x HEXNUM and I have an output that I want to use to be the input for this function.
This output is always in the form of a HEX without 0x so I only want to add 0x before it and store it in any variable so that when I want to call my desired function, I'd call it with the variable that I have just stored.
What's confusing to me is that I cant store this HEX number and add 0x to it using any of the number types (long, int, byte, unsigned long, unsigned long long) because they all lead to the number format changing; meaning that the number does not stay in the appearance that I want which is 0xHEX and the function that I need this input format is IR.sendNEC so even if the format does not matter; i mean if it doesnt matter the number being decimal or hex for example as long as they give the same value eventually, my IR.sendNEC does not work (doesnt switch my TV on/off I mean) unless its input is strictly 0xHEX
I really tried to be as brief as possible :smiley: im so sorry for it being that long but it really is confusing to me!

I have a function that takes as an input a number of the form 0 x HEXNUM and I have an output that I want to use to be the input for this function.

Takes input from where? Show the function, so we're not guessing what you want to do.

it takes the input from the ir signal received as a hex code of this signal. here's the input function:

void loop(){
if (irrecv.decode(&results)) {
                   Serial.println("Receiving");
                   Serial.println(results.value, HEX);
value = results.value; // i dont know how to store the above printed value which is (results.value,HEX)
}
}

and for my sending function that uses this input value, here it is:

for (int i = 0; i < 3; i++) {
            irsend.sendNEC(value,38); //THE PROBLEM LIES IN VALUE!!!
            delay(40);

the problem is that sendNEC does not work except when i give it 0xHEX

problem solved... i only had to change 38 in sendNEC into 32 and i used the value as it is (meaning value=results.value not value = (hex) results.value)
thanks for the help !