How to seperate "active" HEX code from remote that produces lot of "FFFFFF"

Hi there,

I am trying to create a simple sketch to switch things using an IR remote. It works, but I have to press a button several times to get a response and I think this has to do with the HEX code sent out by the remote. (found that with a IR reader)
The code sent shows: FD9A65 FFFFFF FFFFFF FFFFFF etc.
The sketch is meant for an ATTiny85, and like mentioned, it works, but not satisfactory. I think that is caused by the “overwhelming” amount of FFFFFF’s that follow the intended HEX.

So, how do I filter out/ignore those FFFFFF’s in the sketch? Or add something to the sketch to make it recognize the active HEX PLUS one or two FFFFFF’s

(A second question that has come up; why is there no list of commands that one can use, or something like that in the library?)

The sketch:

#include <IRremote.h>

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

int x;

#define code0 0xFD9A65 //Button Power/Standby
#define code1 0xFD1AE5 //Button Subtitle
#define code2 0xFD18E7 //Button Language
#define code3 0xFD9867 //Button Open/Close
#define code4 0xFDB24D //Button Angle

void setup()
{

irrecv.enableIRIn();

pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);

}

void loop()
{
if (irrecv.decode(&results))

{
int x = (results.value);

switch(x) {

case code1:
digitalWrite(0,HIGH);

break;

case code2:
digitalWrite(1,HIGH);

break;

case code3:
digitalWrite(3,HIGH);

break;

case code4:
digitalWrite(4,HIGH);

break;

case code0:
digitalWrite(0,LOW);
digitalWrite(1,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);

break;
}
irrecv.resume(); // Receive the next value
}}

Program uses 76% of memory of the ATTiny. Settings for loading the sketch were:
Clock 8 Mhz internal, BOD disabled, Arduino as SPI.

Where are you seeing these 0xFFFFFFs ?

It seems to be common practice for IR remotes to send 0xFFFFFF as a repeat code when a button is held down on the remote. Is that when you see them ?

 int x = (results.value);

I’m surprised it works at all. You are putting a 32-bit integer (unsigned long) containing a 24-bit number into a 16-bit signed integer. How that ever compares properly with 24-bit constants I do not know.

Hi there! Thanks for your replies!

To UKHeliBob: I see them when I use a small sketch with an uno to read the code of the IR. This way I know which ones to use in the sketch for the ATTiny.
And Yes, the FFFFF's show up immediately after the code when the button is pressed. And yes, I guess I hold the button a fraction too long down. That is why it works sometimes (when I get the "press timing" right.

To Johnwasser: I am a beginner so you may be right, but I am unaware and just tried to make this work and it seemed to work (a bit that is)

Your code, posted properly. Please use code tags.

#include <IRremote.h>

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

int x;

 #define code0  0xFD9A65 //Button Power/Standby
 #define code1  0xFD1AE5 //Button Subtitle
 #define code2  0xFD18E7 //Button Language 
 #define code3  0xFD9867 //Button Open/Close 
 #define code4  0xFDB24D //Button Angle

void setup()
{
 
  irrecv.enableIRIn();
 
   
  pinMode(0,OUTPUT);
  pinMode(1,OUTPUT);
  pinMode(3,OUTPUT); 
  pinMode(4,OUTPUT); 

}

void loop()
{
  if (irrecv.decode(&results))

    {
 int x = (results.value); 
       
 switch(x)  {
   
    case code1:
    digitalWrite(0,HIGH);
       
    break;
   
    case code2:
    digitalWrite(1,HIGH);
   
    break;

    case code3:
    digitalWrite(3,HIGH);
       
    break;
   
    case code4:
    digitalWrite(4,HIGH);
       
    break;
   
    case code0:
    digitalWrite(0,LOW);
    digitalWrite(1,LOW);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
   
    break;
 }
irrecv.resume(); // Receive the next value
}}

Since it seems to work, the compare must be considering only the lowest 16 bits, which are unique in the defined commands.

Add a “default:” case to explicitly ignore commands other than those defined.

Something not immediately obvious about switch ... case:

In

switch (expr) {
  case value1: ...
  case value2: ...
  case value3: ...
}

value1, value2, etc. are converted to the promoted(*) type of expr.

(*) anything smaller than int -> int.

oqibidipo:
Something not immediately obvious about switch ... case:
value1, value2, etc. are converted to the promoted(*) type of expr.

So that explains the warning messages, and how it works at all:

/Users/john/Documents/Arduino/sketch_aug26a/sketch_aug26a.ino: In function 'void loop()':
/Users/john/Documents/Arduino/sketch_aug26a/sketch_aug26a.ino:39:7: warning: overflow in implicit constant conversion [-Woverflow]
       case code1:
       ^
/Users/john/Documents/Arduino/sketch_aug26a/sketch_aug26a.ino:43:7: warning: overflow in implicit constant conversion [-Woverflow]
       case code2:
       ^
/Users/john/Documents/Arduino/sketch_aug26a/sketch_aug26a.ino:47:7: warning: overflow in implicit constant conversion [-Woverflow]
       case code3:
       ^
/Users/john/Documents/Arduino/sketch_aug26a/sketch_aug26a.ino:51:7: warning: overflow in implicit constant conversion [-Woverflow]
       case code4:
       ^
/Users/john/Documents/Arduino/sketch_aug26a/sketch_aug26a.ino:55:7: warning: overflow in implicit constant conversion [-Woverflow]
       case code0:
       ^
Sketch uses 6750 bytes (20%) of program storage space. Maximum is 32256 bytes.
Global variables use 1035 bytes (50%) of dynamic memory, leaving 1013 bytes for local variables. Maximum is 2048 bytes.

Hi there, thanks for your input and apologies for not responding earlier; i was out for a couple of days.

To jremington: I'm afraid I do not know how to put the code in a neat box like you show, so sorry it takes up space and please tell me.
And I have to try figure out how to insert some code to ignore the FFFFFF's. as I'm a beginner.(*)

From johnwasser's comment I understand he responds to the proposed code by oqibidipo? As I do not see any error message when I load my code into the 85.

To oqibidipo: I will try out removing the break statements, although that will not solve my question I think.

(*) FYI: why would a beginner in programming go into ATTiny's? Because I want to build them into Model Railway Scenery.

I have to try figure out how to insert some code to ignore the FFFFFF’s.

Your original code ignores any value other than these 5 values

 #define code0  0xFD9A65 //Button Power/Standby
 #define code1  0xFD1AE5 //Button Subtitle
 #define code2  0xFD18E7 //Button Language 
 #define code3  0xFD9867 //Button Open/Close 
 #define code4  0xFDB24D //Button Angle

So it is already ignoring FFFFFFs

I’m afraid I do not know how to put the code in a neat box like you show

After you have pasted the code here select it all then click the code tags icon ( </> ) top/left of the editor window to add the code tags around the code

Apologies guys,
Finally got it to work. After once more wiggling all the connecting wires and holding the remote (batteries are fine) at close range. (10-15cm). I guess I need to replace the resistor between the 1838 IR sensor and PB2 by a lower value from the presently 10K to make the signal stronger.
The cause of all problems must have been the cheap Chinese breadboard, which made it work every now and then. Tried out variants of the sketch with zero success and got back to the original one.
So here it is: (in a box, thanks to UKHeliBob)

#include <IRremote.h>

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

int x;

 #define code0  0xFD9A65 //Button Power/Standby
 #define code1  0xFD1AE5 //Button Subtitle
 #define code2  0xFD18E7 //Button Language  
 #define code3  0xFD9867 //Button Open/Close  
 #define code4  0xFDB24D //Button Angle 

void setup()
{
  
  irrecv.enableIRIn(); 
  
    
  pinMode(0,OUTPUT);
  pinMode(1,OUTPUT);
  pinMode(3,OUTPUT);  
  pinMode(4,OUTPUT);  

}

void loop()
{
  if (irrecv.decode(&results))

    {
 int x = (results.value);  
        
 switch(x)  {
    
    case code1:
    digitalWrite(0,HIGH);
    break;
    
    case code2:
    digitalWrite(1,HIGH);
    break;

    case code3:
    digitalWrite(3,HIGH);
    break;
    
    case code4:
    digitalWrite(4,HIGH);
    break;
    
    case code0:
    digitalWrite(0,LOW);
    digitalWrite(1,LOW);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    break;
 }
irrecv.resume(); // Receive the next value 
}}

The settings are ATTiny85, 8Mhz internal, BOD disabled, all other variables default.

Why is there a resistor between the TSOP1838 output and the Arduino input? The only resistor I see in the datasheet is in the Vcc line (part of an RC filter to reduce ripple in the power supply).