Go Down

Topic: IRremote.h Library Help (Read 1 time) previous topic - next topic

Manuel Silva

Hello all,

Please help on this problem.

I am using the <IRremote.h> library. I call the reading code as a function, the code I use is bellow. When I send an IR command at the first call of the function I receive the correct code, but, if I call again the function without send a IR command, I get again the same code, I need to call two more times the function to get a zero value.

Below  is the code I am using, and also the code I use to test the return command code.

Thanks in advance.

Manuel

Code: [Select]

uint16_t IR_code()
{
  key=0;
  if (irrecv.decode(&results)) // have we received an IR signal?
  {
     //Serial.println(results.value, DEC); // Imprimir na porta serial o valor do controle
    //lcd.print(results.value, DEC); // Imprimir na porta serial o valor do controle
    switch(results.value)
  {
    case 2107:key=10; break;//Menu
    case 2080:key=11; break;//Up
    case 2081:key=12; break;//Down
    case 2064:key=13; break;//right
    case 2065:key=14; break;//left
    case 2085:key=15; break;//enter
    case 2102:key=16; break;//exit       
    case 2103:key=17; break;//stop     
    case 2049:key=1; break;
    case 2050:key=2; break;     
    case 2051:key=3; break;     
    case 2052:key=4; break;     
    case 2053:key=5; break;
    case 2054:key=6; break;     
    case 2055:key=7; break;     
    case 2056:key=8; break;         
    case 2057:key=9; break;
    case 2048:key=0; break;         
 
    default: key=100;
   
    return key;
  }
  delay(2);
    irrecv.resume(); // receive the next value
  }  // Your loop can do other things while waiting for an IR command
}


Below is the code to test the return code.

Code: [Select]

void pano360()
{
   IR_code();
   key=0;
   uint8_t i=1;
   lcd.setCursor(0, 0);
   lcd.print("  Pano360 Mode  ");     
   lcd.setCursor(0, 1);
   lcd.print("Num. Positions? ");
   lcd.setCursor(0,2);
   lcd.print("                ");
   
   while(i) // Get number of position till OK/enter(15) be pressed
   {
       while (key==0)
       {
       IR_code();
       Serial.print("test0 ");
       Serial.println(key, DEC);
       Serial.println("            ");
       }
         lcd.setCursor(0,2);
         lcd.print(key,DEC);
         delay(3000);
                     
       Serial.print("test1 = ");
       Serial.println(key, DEC);
       Serial.println("            ");
       key=0;
      //i=0;
   }
}   

pylon

If you consumed a code with:

Code: [Select]
irrecv.decode(&results)

you should always call

Code: [Select]
irrecv.resume()

but you don't, you return the generated key.

BTW: you return the key value but you use the global variable for the value transfer. Either use a global variable in all cases or stick with local variables and return the value.

Manuel Silva

Pylon,

Thanks for your help. I am going to follow your advise.

Regards,
Manuel

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy