Problem with IR-control WS2801 and WS2812B leds

Hi,

i got a strange problem (for me).
for a project i have WS2812B leds build in a lamp.
i wrote code using WS2801 leds because the ws2812b haven't arrived yet.
the leds are controlled with an IR-remote and with the WS2801 strip everything works ok.

but when i change the led to WS2812B the remote doesn't work anymore.
the code it self works, but it goes crazy.

when i push button 1 on the remote it gives value 255
when i change the code to the WS2812B leds it gives complete other codes and everytime you push the same button you get an other value.

the code below is for the WS2801

changes made for the ws2812b are:

the // before "define data_pin 6 " are removed
and in void setup
FastLED.addLeds<WS2801, BGR>(leds, NUM_LEDS);
becomes
FastLED.addLeds<WS2812b, DATA_PIN, GRB>(leds, NUM_LEDS);

the code is maybe not the best but i am not a pro :wink:

hope someone can help me with this, or knows hw to fix it.

Mark

// ir sectie

#include <IRremote.h>
int RECV_PIN = 3;

    #define code1  255
    #define code2  32895
    #define code3  16575
    #define code4  49215
    #define code5  8415
    #define code6  41055
    #define code7  24735
    #define code8  57375 
    #define code9  4335
    #define code10 36975
    #define code11 20655
    #define code12 53295
    #define code13 12495
    #define code14 45135
    #define code15 28815
    #define code16 61455
    #define code17 2295
    #define code18 34935
    #define code19 18615
    #define code20 51255
    #define code21 10455
    #define code22 43095
    #define code23 26775
    #define code24 59415
    
IRrecv irrecv(RECV_PIN);
    decode_results results;
    
// fastled
  #include "Arduino.h"
  #include <FastLED.h>
 // #define DATA_PIN 6
  #define NUM_LEDS 40
  CRGB leds[NUM_LEDS];
  
//control
  
int program = 4;
int Brightness = 200;
int Brightnessorg = 0;
int knipper = 0;
int randNumber1 = 0;
int randNumber2 = 0;
int randNumber3 = 0;

// lichtorgel
#define soundpin 8  
int sound;

// twinkle

#define DENSITY 255

    
void setup() {
  
   Serial.begin(9600);   // you can comment this line

// ir  
   irrecv.enableIRIn();  // Start the receiver
   irrecv.blink13(true); 

// Ledstrip      
   FastLED.addLeds<WS2801, GRB>(leds, NUM_LEDS);

// licht orgel
   pinMode(soundpin, INPUT);
}

void loop() {
  
 FastLED.setBrightness(Brightness);
 //Serial.println(program);
 //Serial.println(Brightness);

// check IR
 ir();
 StartProgram();
}

void StartProgram() {
   if (program == 3) {
     uit();
   }
   if (program == 4){
    aan();  
   }
   if (program == 5){
   knipper = 5;
   rood();  
   }
   if (program == 6){
    knipper = 6;
    groen();  
   }
   if (program == 7){
     knipper = 7;
    blauw();  
   }
   if (program == 8){
     knipper = 8;
    wit();  
   }
   if (program == 9){
     knipper = 9;
    magenta();  
   }
   if (program == 10){
    knipper = 10;
   LimeGreen();  
   }
   if (program == 11){
    hblue();  
   }
   if (program == 12){
    flash();  
   }
   if (program == 13){
    knipper = 13;
    DarkOrange();  
   }
   if (program == 14){
    hLimeGreen();  
   }
   if (program == 15){
    uit();  
   }
   if (program == 16){
    lichtorgel();  
   }
   if (program == 17){
    uit();  
   }
   if (program == 18){
    DeepSkyBlue();  
   }
   if (program == 19){
    hMagenta;  
   }
   if (program == 20){
    softtwinkles();  
   }
   if (program == 21){
    looplicht();  
   }
   if (program == 22){
    lichtorgel();  
   }
   if (program == 23){
    hsmooth();  
   }
   if (program == 24){
    smooth();  
 }
 
}

void ir() {
 // static int brn = 200;
 //FastLED.setBrightness(brn);
 if (irrecv.decode(&results)) {
        unsigned int value = results.value;
        switch(value) {
           case code1:
                Brightness = Brightness + 10;
                if (Brightness >= 255) {
                  Brightness = 255;
                }
               // Serial.println(Brightness); 
                FastLED.show();
                break;

           case code2:
               Brightness = Brightness - 10;
               if (Brightness <= 5) {
                Brightness = 5;
                }       
              
              // Serial.println(Brightness); 
               FastLED.show();
               break;
          case code3:
               program = 3;
               break;
          case code4:
               program = 4;
               break;
          case code5:
               program = 5;
               break; 
          case code6:
               program = 6;
               break;
          case code7:
               program = 7;
               break; 
          case code8:
               program = 8;
               break; 
          case code9:
               program = 9;
               break;
          case code10:
               program = 10;
               break;
          case code11:
               program = 11;
               break;    
          case code12:
               program = 12;
               break;
          case code13:
               program = 13;
               break;
          case code14:
               program = 14;
               break;   
          case code15:
               program = 15;
               break;
          case code16:
               program = 16;
               break; 
          case code17:
               program = 17;
               break; 
          case code18:
               program = 18;
               break;         
          case code20:
               program = 20;
               break;
          case code21:
               program = 21;
               break;
          case code22:
               program = 22;
               break;    
          case code23:
               program = 23;
               break;    
          case code24:
               program = 24;
               break;           
        }
        Serial.println  (value); // you can comment this line
        
        irrecv.resume(); // Receive the next value
      }
}

void aan() {
fill_solid( leds, NUM_LEDS, CRGB::White);
FastLED.show();
}

void aan2() {
fill_solid( leds, (20,40), CRGB::NavajoWhite);
fill_rainbow(leds, 20, 0, 12.75);
FastLED.show();
}

void haan2() {
fill_solid( leds, (20,40), CRGB::Black);
fill_rainbow(leds, 20, 0, 12.75);
FastLED.show();
}

void uit() {
fill_solid( leds, NUM_LEDS, CRGB::Black);
FastLED.show();
}

void rood() {
fill_solid( leds, NUM_LEDS, CRGB::Red);
FastLED.show();
}

void groen() {
fill_solid( leds, NUM_LEDS, CRGB::Green);
FastLED.show();
}

void blauw() {
fill_solid( leds, NUM_LEDS, CRGB::Blue);
FastLED.show();
}

void hblue() {
fill_solid( leds, NUM_LEDS, CRGB::Black);
FastLED.show();
fill_solid( leds, (0,20), CRGB::Blue);
FastLED.show();
}

void wit() {
fill_solid( leds, NUM_LEDS, CRGB::White);
FastLED.show();
}

void magenta() {
fill_solid( leds, NUM_LEDS, CRGB::Magenta);
FastLED.show();
}

void LimeGreen() {
fill_solid( leds, NUM_LEDS, CRGB::LimeGreen);
FastLED.show();
}

void hLimeGreen() {
fill_solid( leds, NUM_LEDS, CRGB::Black);
fill_solid( leds, (0,20), CRGB::LimeGreen);
FastLED.show();
}

void DeepSkyBlue() {
fill_solid( leds, NUM_LEDS, CRGB::DeepSkyBlue);
FastLED.show();
}

void DarkOrange() {
fill_solid( leds, NUM_LEDS, CRGB::DarkOrange);
FastLED.show();
}

void DeepPink() {
fill_solid( leds, NUM_LEDS, CRGB::DeepPink);
FastLED.show();
}

void hMagenta() {
fill_solid( leds, NUM_LEDS, CRGB::Black);
fill_solid( leds, (0,20), CRGB::Magenta);
FastLED.show();
}

void flash() {  
 
   if (knipper == 5){
   rood();  
   }
   if (knipper == 6){
    groen();  
   }
   if (knipper == 7){
    blauw();  
   }
   if (knipper == 8){
    wit();  
   }
   if (knipper == 9){
    magenta();  
   }
   if (knipper == 10){
   LimeGreen();  
   }
   
   
   if (knipper == 13){
    DarkOrange();  
   }
   if (knipper == 14){
    uit();  
   }
   if (knipper == 15){
    uit();  
   }
   if (knipper == 17){
    uit();  
   }
   if (knipper == 18){
    uit();  
   }
  if (knipper == 19){
    uit();  
   }
   
delay(500);
fill_solid( leds, NUM_LEDS, CRGB::Black);
FastLED.show();
delay(500);
}

void smooth() {
static int j = 0;
fill_rainbow(leds, NUM_LEDS,(0, j), 6.375);
FastLED.show(); 
j++;
  if (j == 255) {
    j = 0;
  } 
  FastLED.delay(200);
}

This is a common enough problem with WS2811/12 style leds that I've written up a wiki page on the FastLED site about it:

FastLED Interrupt Problems - https://github.com/FastLED/FastLED/wiki/interrupt-problems

But the short version is when it comes to the trio of "avr based arduino", "ws2812 leds", "IR control" - you can pick two :slight_smile:

One thing you could possibly try doing, however, is call

    irrecv.resume();

after calling FastLED.show(). This will reset the state of the IR decoder, and hopefully clear up any corrupted data caused by FastLED's disabling of interrupts.

thanx will try...