0

I'm a big noob when it comes to writing a sketch and have set myself a task for an upcoming 4th July project, which has come to a halt.

I'm trying to set a strip of 30 LEDs to fade from red to white to blue through FastLED on a Wemos D1 mini. I also wanted it to flash each colour after the 3 colours have faded and continuously loop these.

I have searched many different forums and managed to get the fade to go from red to blue, but can't for love nor money add the white in-between.

Can someone point me in the right direction?

#include "FastLED.h"
#define NUM_LEDS 30
#define DATA_PIN D4
#define COLOUR_ORDER GRB

CRGB leds[NUM_LEDS];

void setup() { 

    FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);

}
void loop(){

    //start from red
    for( int colorStep=0; colorStep <= 255; colorStep++ ) {

        int r = 255;
        int g = 0;
        int b = colorStep;

        // Now loop though each of the LEDs and set each one to the current color
        for(int x = 0; x < LED_COUNT; x++){
            leds[x] = CRGB(r,g,b);
        }

        // Display the colors we just set on the actual LEDs
        delay(10); 
        FastLED.show();
    }

    //into blue
    for( int colorStep=255; colorStep >= 0; colorStep-- ) {

        int r = colorStep;
        int g = 0;
        int b = 255;

        // Now loop though each of the LEDs and set each one to the current color
        for(int x = 0; x < LED_COUNT; x++){
            leds[x] = CRGB(r,g,b);
        }

        // Display the colors we just set on the actual LEDs
        delay(10); 
        FastLED.show();
    }
}
gre_gor
  • 1,680
  • 4
  • 18
  • 28
Benjini
  • 11
  • 2

1 Answers1

-1

Think of a color as a point in 3d as defined by its r g b attributes

Think of two points here, one is your starting color in that 3d space, and another your ending color.

Figure out the path you want to take from the starting color to the ending cokor.

Chop it up in a few steps and use your code to walk the path.

Done

dannyf
  • 2,770
  • 10
  • 13