RGB WS2812B Leds strips fastLED for Chaser & Fading at the same time

Hi All!

I’m not an expert but I try hard until I smash on the floor, saw tons of videos and searched online :confused: That’s why I’m writing here for help. I’ve been working with no luck to get an effect with my RGB ws2812b 50 led strip. I want to get the effect of chasing & fading two colors (red & white) at the same time, ie. red chasing the white (35 reds & 15 whites) and the chase having the fade effect between red and white.

I tried different sketches but I got them running separately. Below is the fading one but with no chasing. Any suggestions? Thanks in advance!!

Martín

#include "FastLED.h"
#define LED_PIN 3
#define NUM_LEDS 50
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
#define BRIGHTNESS  75 
int fadeTime = 10000; //In milliseconds;
bool fadeDirection = false;

CRGB leds[NUM_LEDS];

void setup() {
  LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
  }
  


void loop() {
   for(int i = 0; i < NUM_LEDS; i++ ){
   leds[i+15].´´(0, 255, 0);
   leds[i+45].setRGB(252, 206, 185);  // Set Color HERE!!!
   leds[i+25].fadeLightBy( 64 );
   FastLED.show();
   delay(200);  // This delay sets speed of the fade. I usually do from 5-75 but you can always go higher.
   }
   FastLED.clear();
  
}

Your loop has some problems. You never address LEDs 0-14, and I suspect that you don’t grok the fade commands. It took me a while as well.

From the docs:
“Colors are always dimmed down by a fraction. The dimming fraction is expressed in 256ths, so if you wanted to dim a color down by 25% of its current brightness, you first have to express that in 256ths. In this case, 25% = 64/256.”

// Dim a color by 25% (64/256ths)
// using "video" scaling, meaning: never fading to full black
leds[i].fadeLightBy( 64 );

Meaning that every time you set an LED to fadeLightBy(64), then fastLED.show(), that LED gets dimmed by 25% of its current value. To dim it to 1 (it will not go to zero) you have to hit it four times.

fadeToBlack works the same way, but it will fade the LED to 0.

Here is a example program that I modified that does mostly what you want. You need to change your LED pin#, Type, etc. and the colors you want to chase.

/*
  ****************************************************************
   fastLED_Cylon.ino

   Example of defining a CRGB color using Hex,
   and passing that to a function.

   Modified the code by Marc Miller, Feb 2017
 ****************************************************************
*/


#include "FastLED.h"
#define DATA_PIN    D2
#define LED_TYPE    WS2811
#define COLOR_ORDER RGB
#define NUM_LEDS   50

#define BRIGHTNESS  100

CRGB leds[NUM_LEDS];

#define MGPu CRGB(0x8010ff) // Mardi Gras Purple
#define MGGr CRGB(0x2cb004) // Mardi Gras Green
#define MGGo CRGB(0xff4a00) // Mardi Gras Gold


//---------------------------------------------------------------
void setup() {
  Serial.begin(115200);   // Allows serial monitor output (check baud rate)
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
}


//---------------------------------------------------------------
void loop() {
  cylon(MGPu);  // Purple.  (Call cylon function with this color.)
  cylon(MGGr);  // Green
  cylon(MGGo);  // Gold
}


// ========================== cylon ==========================
void cylon(CRGB streakcolor) {
  // Forward
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = streakcolor;
    FastLED.show();
    fadeall();
    delay(10);
  }
  // Reverse
  for (int i = (NUM_LEDS) - 1; i >= 0; i--) {
    leds[i] = streakcolor;
    FastLED.show();
    fadeall();
    delay(10);
  }
}


// ========================== fadeall ==========================
void fadeall()  {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i].nscale8(250);
  }
}

Thank you Steve! It worked perfectly! really appreciate your help!