Compare two informations

I want to compare two informations, so when the correct value is read it is sent to serial monitor.

Instead I get only hex values from the first if statement.

What am I doing wrong?

int FF10EF;

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

You have defined a variable called FF10EF, but not assigned a value to it.

I think you probably wanted to use a literal hexadecimal value, not a variable.

Literal hexadecimal values are prefixed with 0x and you most certainly don't want to define a literal as an integer variable.

Also, what is (results.value, HEX) supposed to achieve? HEX is only meaningful in the context of a print statement. Remember - hexadecimal is only a human readable representation of a number - internally it's a collection of 1's and 0's.

  if (results.value == 0xFF10EF) {

You mix up the value of a variable and its human readable representation. Serial.print() gives a human readable format (most of the time :wink:

Read the code below, try to understand the difference and then give it a try.

unsigned long rightValue = 0xFF10EF;

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

update: removed/commented bug from code

HEX because I convert result to hex format for shorter readable output. "FF10EF" is hex value converted from result value.
I want to compare, if the converted result value in hex is the same as the hex I want (FF10EF).

majenko:

  if (results.value == 0xFF10EF) {

Thanks majenko. Never used 0x before.
Problem not solved completely. Now when I get exact hex, the program loops the whole if statement, so only "levo" is printed out on serial. No other functions work.

I think you need to restructure your "if" statements.

Something more like:

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

That way you only do one resume instead of two, and you only check the value once you know there is a real value there.

I solved the problem like this

results.value = 0

Thanks anyway.