Hi All, I'm just starting with FastLED,

Hi All,

I’m just starting with FastLED, trying to write a simple fade in-out function. Here’s relevant code:

void loop() {
int s = cos8(x);
x++;
if (x == 256) x=0;
for (int j = 0; j < NUM_LEDS; j++) {
leds[j].setRGB(255, 0, 0);
leds[j].fadeLightBy(s);
}
FastLED.show();
delay(20);
}

This works, but LEDs flicker and turn off at very low brightness levels. I’m using WS2812B LEDs, at the moment.

How can I fix this, and how can I apply color correction? Thanks in advance.

Hello @Mitch_Feig You can add a color correction tweak by adding .setCorrection on the end of the addLeds line:

FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS).setCorrection(255,128,64);

The above example would knock the green down by 50%, and blue down by 75%.

Thanks, Marc. I see that class in the documentation, but for some reason I’m getting a no matching function for call, error.

Is there a better way to do this than the code below? I’d like a smooth transition from one color to the next, at the lowest point of the sine wave, but I’m still getting some flicker, and no colors for a few cycles.

EVERY_N_MILLISECONDS(30) {
int s = sin8(x);
if (x > 254 ) x = 0;

for (int j = 0; j < NUM_LEDS; j++) {
  leds[j].setRGB(r, g, b);
      leds[j].fadeLightBy(s);

}
FastLED.show();
  
if (s == 254) {
       switch (col) {
  case 0:
    r = 255;
    g = 0;
    b = 0;
    break;
  case 1:
    r = 255;
    g = 255;
    b = 255;
    break;
  case 2:
    r = 0;
    g = 0;
    b = 255;
    break;
}
  col++;
  if (col == 3) col = 0;
}
x++;

}

This is pretty much the same thing, but seems to be running pretty smooth for me:

uint8_t s = 0;
uint8_t x = 0;
uint8_t r = 0;
uint8_t g = 0;
uint8_t b = 0;
uint8_t col = 0;
void loop() {

s = sin8(x);
if (x > 254 ) x = 0;

for (int j = 0; j < NUM_LEDS; j++) {
leds[j].setRGB(r, g, b);
leds[j].fadeLightBy(s);
}

FastLED.show();

if (s == 254) {
switch (col) {
case 0:
r = 255;
g = 0;
b = 0;
break;
case 1:
r = 255;
g = 255;
b = 255;
break;
case 2:
r = 0;
g = 0;
b = 255;
break;
}
col++;
if (col == 3) col = 0;
}
x++;

FastLED.delay(30);
}