0

I am trying to make a remote controlled robot with Arduino and the IR remote control is kinda weird. When I press a button, sometimes I get the right hex value, other time I get the hold value FFFFFF.

How can I implement some code so that I can, for example, run the motors as long as I hold the button or detect which button it was since the hold code is the same for all codes?

Since I know that the hold value is 0xFFFFFFFF, is there a function that:

(any hex not 0xffff) func(OR?) (0xffffffff) = (any hex ...)

and

( 0xfffff)           func (0xffffff)   != (0xffffff)

Or do I need to implement some kind of state machine? It is kinda difficult with the delay() as well.

By the way, I'm using Keyes KY 022. What are the signal length times? (I don't have an oscilloscope).

Maybe would be useful to set the press value to other? Or to ignore it?

LE: And some code to test: one single key:

Maybe other libraries are interrupting the timer...

    #include <IRremote.h>
    #define IR_PIN 11
    IRrecv irrecv(IR_PIN);
    decode_results results;
    long int Key;
    const unsigned long int UP = 0x00FF629D;
    const unsigned long int DOWN = 0x00FFA857;
    const unsigned long int LEFT = 0x00FF22DD;
    const unsigned long int RIGHT = 0x00FFC23D;
    const unsigned long int OK = 0x00FF02FD;
    const unsigned long int k1 = 0x00FF6897;// C101E57B
    const unsigned long int k2 = 0x00FF9867;// 97483BFB
    const unsigned long int k3 = 0x00FFB04F;// F0C41643
    const unsigned long int k4 = 0x00FF30CF;
    const unsigned long int k5 = 0x00FF18E7;
    const unsigned long int k6 = 0x00FF7A85;
    const unsigned long int k7 = 0x00FF10EF;
    const unsigned long int k8 = 0x00FF38C7;
    const unsigned long int k9 = 0x00FF5AA5;
    const unsigned long int STAR = 0x00FF42BD;
    const unsigned long int k0 = 0x00FF4AB5;
    const unsigned long int HASH = 0x00FF52AD;
    const unsigned long int HOLD = 0xFFFFFFFF;

   void setup(){
   // put your setup code here, to run once:
      Serial.begin(9600);
      delay(2000); while (!Serial);
      irrecv.enableIRIn();
  //irrecv.blink13(true);
  //setup1(); From IRremoteInfo TAB   
   }
char buff[1000];
unsigned long int msg;
void processIR(unsigned long int msg)
{
  sprintf(buff, "READ IR %x \n", results.value);
  Serial.print(buff);
  switch (msg)
  {
    case UP:
      Serial.println("UP");
      break;
    case DOWN:
      Serial.println("DOWN");
      break;
    case LEFT:
      Serial.println("LEFT");
      break;
    case RIGHT:
      Serial.println("RIGHT");
      break;
    case k1:
      Serial.println("k1");
      break;
    case k2:
      Serial.println("k2");
      break;
    case k3:
      Serial.println("k3");
      break;
    case k4:
      Serial.println("k4");
      break;
    case k5:
      Serial.println("k5");
      break;
    case k6:
      Serial.println("k6");
      break;
    case k7:
      Serial.println("k7");
      break;
    case k8:
      Serial.println("k8");
      break;
    case k9:
      Serial.println("k9");
      break;
    case STAR:
      Serial.println("STAR");
      break;
    case k0:
      Serial.println("k0");
      break;
    case HASH:
      Serial.println("HASH");
      break;
    case HOLD:
      Serial.println("HOLD");
      break;
      //case default:
      //    delay(500);
      //       irrecv.decode(&results);
      //       msg = results.value;
      //       processIR(msg);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  if (irrecv.decode(&results))
  {
    irrecv.resume();
    char buff[255];
    sprintf(buff, "Val %010x \n " , results.value );
    Serial.print(buff);
    //results.decode();
    //results.DumpResults();
    //      msg = results.value;
    //      Serial.println(msg, HEX);
    //      Serial.println(results.decode_type);
    //      processIR(msg);

  }


}

And values, of course:

 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x000002fd 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x000022dd 
 Val 0x0000ffff 
 Val 0x0000c23d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000ffff 
 Val 0x0000ffff 
 Val 0x0000ffff 
 Val 0x0000ffff 
 Val 0x0000ffff 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x00005282 
 Val 0x000038d6 
 Val 0x0000ffff 
 Val 0x0000efb5 
 Val 0x00006897 
 Val 0x00006897 
 Val 0x00006897 
 Val 0x0000ffff 
 Val 0x00006897 
 Val 0x00006897 
 Val 0x0000ffff 
 Val 0x00006897 
 Val 0x00009867 
 Val 0x00009867 
 Val 0x0000b04f 
 Val 0x0000ffff 
 Val 0x00004794 
 Val 0x00009424 
 Val 0x0000ffff 
 Val 0x000042bd 
 Val 0x0000ffff 
 Val 0x00004ab5 
 Val 0x0000ffff 
 Val 0x000052ad 
 Val 0x0000ffff 
 Val 0x00004ab5 
 Val 0x00005aa5 
 Val 0x0000ffff 
 Val 0x000038c7 
 Val 0x000010ef 
 Val 0x0000ffff 
 Val 0x000030cf 
 Val 0x0000ffff 
 Val 0x000018e7 
 Val 0x0000ffff 
 Val 0x00007a85 
 Val 0x0000ffff 
 Val 0x00004ec5 
 Val 0x00007a2a 
 Val 0x00007d4f 
 Val 0x0000a33f 
 Val 0x00007a28 
 Val 0x00008dd8 
 Val 0x00004b78 
 Val 0x0000144b 
 Val 0x00006781 
 Val 0x0000040a 
 Val 0x0000ffbf 
 Val 0x00007d4f 
 Val 0x0000ee7c 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 
 Val 0x0000629d 
 Val 0x0000ffff 

So each press of a key gives 2 values.

  • char buff[1000]; - what Arduino is this? You know Arduinos generally don't have a lot of RAM? Using 1000 bytes to hold READ IR abcd \n seems a little excessive. – Nick Gammon Jan 13 '16 at 2:09
  • Yes, I know. Was just testing ... Maybe the real question when I changed the size was if "sprintf() overflows" Maybe it is, but it just overflowed, but didn't had any shellcode. – Florin Jan 20 '16 at 21:19
1

If I understand your question correctly, a button press will first generate a distinct hex code, and then after a while a series of 0xFFFFFF?

In that case, why don't you simply store the last distinct code you received, and replace occurrences of 0xFFFFFF with the stored code?

| improve this answer | |
0

I found out that by adding this while loop to an IRremote use, the code after it won't run until the button is released.

while(irrecv.decode(&results)){
    irrecv.resume();
    delay(150);
}

This will keep the buttons pressed if the code at the end on loop() ends the input.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.