Problem with IF data

I have a sketch where a different LED pattern will play depending on what button is pressed on the remote. The issue I'm having is that I am getting different data each time I press the same button on the remote. I've tried different remotes and have the same issue. For example here is the serial monitor output of "results.value", pressing the same button there are many different values:

2351064443
4294967295
2318639606
16716015
2780749627
255
2351064443
2351064443
255
2351064443
2351064443
4294967295
3581587197
16716015
2468911386

Any idea why this is happening? Here is the code:

#include <IRremote.h>
 

const int RECV_PIN =2;
 

IRrecv irrecv(RECV_PIN);
decode_results results;
 
unsigned long startMillis;  //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 1000;  //the value is a number of milliseconds

#include "FastLED.h"
#define NUM_LEDS 19  // # of LEDS in the strip
CRGB leds[NUM_LEDS];
CRGB leda[NUM_LEDS];
#define PIN 8
#define PINA 11 // Output Pin to Data Line on Strip
#define COLOR_ORDER GRB  // I had to change this for my strip if your color is off then you know.




void setup() {

   FastLED.addLeds<WS2812B, PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.addLeds<WS2812B, PINA, COLOR_ORDER>(leda, NUM_LEDS).setCorrection( TypicalLEDStrip );

  Serial.begin(9600);
  irrecv.enableIRIn();

     
  }
}
void loop() {

   if (irrecv.decode(&results)){
         Serial.println(results.value);
        irrecv.resume();
  }

  
  
switch (results.value)

{
case 16716015:
bluechase();
break;

case 4294967295:
ebright();
break;

case 484655295:
construction();
break;

probably a challenge between IRremote and FastLED. too much pressure on the interrupt system possibly

test a program JUST with the IR and print what you get.

If FastLEDs has critical timing, it will disable interrupts when the data is being sent, which is not good news for the IR receiver.

Is there any suggested workarounds? Testing a script with IR only was better but it renders the IR useless if I can't use it with other scripts:

2351064443
2351064443
2351064443
16716015
2351064443
2351064443
4294967295
2351064443
2351064443
2351064443
2351064443
2351064443

You are trying to do too much with your small arduino...

either you Get rid of your WS2812B and buy some APA102. they are more expensive, but they don't put any pressure on the interrupts because they don't need a specific refresh frequency

or you could use 2 arduino, one for decoding the IR and then sending a message to the Arduino driving the LEDs

Try writing the code so you require 2 remote button presses.

The first press is thrown away but it does set a flag that is used to ‘stop’ subsequent Fastled routines.

Since the Fastled code is in a frozen state after the first button press the next button press is free to to be processed and decoded.

Based on the 2nd press the Fastled code is set to the new pattern and then enabled to run.

For switch /case, the variable and the labels must be int or char. This is not your case.

lesept:
For switch /case, the variable and the labels must be int or char. This is not your case.

They must be integer compile-time constants. Who said they had to be of type "int"?

From arduino reference, but maybe I understand wrongly (not native English speaker)

Parameters
var: a variable whose value to compare with various cases. Allowed data types: int, char
label1, label2: constants. Allowed data types: int, char

I'm not (responsible for) / (guilty of) anything written in Arduino's name, but the language allows any integer data-type.

lesept:
From arduino reference, but maybe I understand wrongly (not native English speaker)

better to trust the C/C++ reference guide and not Arduino :slight_smile:

an integral type is bool, char, char8_t, char16_t, char32_t, wchar_t, short, int, long, long long, or any implementation-defined extended integer types, including any signed, unsigned, and cv-qualified (const and volatile) variants.

Add that the "enum type"

Damn it ! Who to trust these days ? ? ?

lesept:
Damn it ! Who to trust these days ? ? ?

Politicians?

Try again... (I'm French)

Damn it ! . . . (I'm French) :slight_smile:

Politicians?

OMG NOOOOOOOOO!

lesept:
Try again... (I'm French)

A gilet jaune?

No
Although I supported them at the beginning, I am like most people here getting bored by the movement

lesept:
No
Although I supported them at the beginning, I am like most people here getting bored by the movement

Why? Everyone has to have a gilet jaune in their car, n'est pas?

Yes, I bought enough gilets for my two cars and my whole family, and they stay in the cars