Custom Color Running Lights on WS2812B

Hi all,

I have become increasingly frustrated lately with libraries for Neopixels, as I can't seem to find anything about how to set up a simple LED strip with a running light effect in specific color sequences.

I have 7 very specific RGB color values that I want to display in sequence, each fading to the next, and I have absolutely no idea how to do it. I got close using the FastLED library, but I cannot for the life of me figure out how to define my colors, all of my attempts have led to a compilation error. No other libraries seem to allow me to define my colors as I want, or if they do, I don't understand how.

I'm running an Arduino Nano with WS2812B pixels, for reference. Attached is my code, based on the Color Palette example from the FastLED library.

ColorPalette1.ino (1.58 KB)

You know how mappers map on set of numbers to another? Drop in x out pops your y value.

A non linier mapper maps pairs of x,y points. (A curve) enter x, gives y..

A non linier color mapper maps pars of colors. (x,RGB Color). Enter x gives a calculated color value.

In your handy Library manager find and instal LC_basetools. Then have a look at colorObj.h

P.S. If you like what you see in colorObj.h there is another library under my signiture line LC_neoPixel. That gives you a neoPixel object that takes colorObj(s) as input and output.

-jim lee

Please post your code within </> code-tags

Deva_Rishi:
Please post your code within </> code-tags

#include <FastLED.h>

#define LED_PIN     9
#define NUM_LEDS    18
#define BRIGHTNESS  255
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 5


CRGBPalette16 currentPalette;
TBlendType    currentBlending;


void setup() {
    delay( 3000 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.setBrightness(  BRIGHTNESS );
    GreenMachine();
    currentBlending = LINEARBLEND;
}


void loop()
{
    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; /* motion speed */
    
    FillLEDsFromPaletteColors( startIndex);
    
    FastLED.show();
    FastLED.delay(1000 / UPDATES_PER_SECOND);
}

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
    uint8_t brightness = 255;
    
    for( int i = 0; i < NUM_LEDS; ++i) {
        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;
    }
}

// Attempt to define custom RGB colors as a palette, then index them in order: does not compile. No clue why.
void GreenMachine()
{
    
    CRGB black  = CRGB::Black;
    CRGB color1 = CRGB(163,  10,  10);
    CRGB color2 = CRGB(249,  65, 252);
    CRGB color3 = CRGB(  0,   0, 255);
    CRGB color4 = CRGB(  0, 255, 213);
    CRGB color5 = CRGB(  6, 163,   3);
    CRGB color6 = CRGB(  0, 191, 159);
    CRGB color7 = CRGB(125,   0, 209);
    
    currentPalette = CRGBPalette16(black, color1, color2, color3, color4, color5, color6, color7, black);
}

Care to share the compiler errors?

Why do you need to use a color palette for ths?

Attached is a photo of the compiler error I get.

I'm using the palette because that's the only way I understand to index the colors such that they appear in the proper order, with the effect I want. This is based on the "purple and green stripes" effect from the FastLED example.

I don't really understand enough of the different Neopixel libraries to figure out alternative methods, and I haven't been able to find any good examples of anyone else doing this.

Pictures of error messages are useless. There's a button in that orange strip that says "Copy error messages".

Click than then post the error messages as text. Extra points if you post it in Code Tags as you did when you posted your script.

Compiling sketch...

"S:\\Program Files\\Arduino 1.8.13\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IS:\\Program Files\\Arduino 1.8.13\\hardware\\arduino\\avr\\cores\\arduino" "-IS:\\Program Files\\Arduino 1.8.13\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "-IC:\\Users\\Emmett\\Documents\\Arduino\\libraries\\FastLED\\src" "C:\\Users\\Emmett\\AppData\\Local\\Temp\\arduino_build_573315\\sketch\\ColorPalette1.ino.cpp" -o "C:\\Users\\Emmett\\AppData\\Local\\Temp\\arduino_build_573315\\sketch\\ColorPalette1.ino.cpp.o"

In file included from C:\Users\Emmett\Documents\Arduino\ColorPalette1\ColorPalette1.ino:1:0:

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/FastLED.h:14:21: note: #pragma message: FastLED version 3.004.000

 #    pragma message "FastLED version 3.004.000"

                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\ColorPalette1\ColorPalette1.ino: In function 'void GreenMachine()':

ColorPalette1:60:104: error: no matching function for call to 'CRGBPalette16::CRGBPalette16(CRGB&, CRGB&, CRGB&, CRGB&, CRGB&, CRGB&, CRGB&, CRGB&, CRGB&)'

     currentPalette = CRGBPalette16(black, color1, color2, color3, color4, color5, color6, color7, black);

                                                                                                        ^

In file included from C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/FastLED.h:58:0,

                 from C:\Users\Emmett\Documents\Arduino\ColorPalette1\ColorPalette1.ino:1:

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:818:5: note: candidate: CRGBPalette16::CRGBPalette16(TProgmemRGBGradientPalette_bytes)

     CRGBPalette16( TProgmemRGBGradientPalette_bytes progpal )

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:818:5: note:   candidate expects 1 argument, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:790:5: note: candidate: CRGBPalette16::CRGBPalette16(const CRGB&, const CRGB&, const CRGB&, const CRGB&)

     CRGBPalette16( const CRGB& c1, const CRGB& c2, const CRGB& c3, const CRGB& c4)

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:790:5: note:   candidate expects 4 arguments, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:786:5: note: candidate: CRGBPalette16::CRGBPalette16(const CRGB&, const CRGB&, const CRGB&)

     CRGBPalette16( const CRGB& c1, const CRGB& c2, const CRGB& c3)

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:786:5: note:   candidate expects 3 arguments, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:782:5: note: candidate: CRGBPalette16::CRGBPalette16(const CRGB&, const CRGB&)

     CRGBPalette16( const CRGB& c1, const CRGB& c2)

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:782:5: note:   candidate expects 2 arguments, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:778:5: note: candidate: CRGBPalette16::CRGBPalette16(const CRGB&)

     CRGBPalette16( const CRGB& c1)

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:778:5: note:   candidate expects 1 argument, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:773:5: note: candidate: CRGBPalette16::CRGBPalette16(const CHSV&, const CHSV&, const CHSV&, const CHSV&)

     CRGBPalette16( const CHSV& c1, const CHSV& c2, const CHSV& c3, const CHSV& c4)

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:773:5: note:   candidate expects 4 arguments, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:769:5: note: candidate: CRGBPalette16::CRGBPalette16(const CHSV&, const CHSV&, const CHSV&)

     CRGBPalette16( const CHSV& c1, const CHSV& c2, const CHSV& c3)

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:769:5: note:   candidate expects 3 arguments, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:765:5: note: candidate: CRGBPalette16::CRGBPalette16(const CHSV&, const CHSV&)

     CRGBPalette16( const CHSV& c1, const CHSV& c2)

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:765:5: note:   candidate expects 2 arguments, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:761:5: note: candidate: CRGBPalette16::CRGBPalette16(const CHSV&)

     CRGBPalette16( const CHSV& c1)

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:761:5: note:   candidate expects 1 argument, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:707:5: note: candidate: CRGBPalette16::CRGBPalette16(const uint32_t (&)[16])

     CRGBPalette16( const TProgmemRGBPalette16& rhs)

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:707:5: note:   candidate expects 1 argument, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:686:5: note: candidate: CRGBPalette16::CRGBPalette16(const CHSV*)

     CRGBPalette16( const CHSV rhs[16])

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:686:5: note:   candidate expects 1 argument, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:680:5: note: candidate: CRGBPalette16::CRGBPalette16(const CHSVPalette16&)

     CRGBPalette16( const CHSVPalette16& rhs)

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:680:5: note:   candidate expects 1 argument, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:665:5: note: candidate: CRGBPalette16::CRGBPalette16(const CRGB*)

     CRGBPalette16( const CRGB rhs[16])

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:665:5: note:   candidate expects 1 argument, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:661:5: note: candidate: CRGBPalette16::CRGBPalette16(const CRGBPalette16&)

     CRGBPalette16( const CRGBPalette16& rhs)

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:661:5: note:   candidate expects 1 argument, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:650:5: note: candidate: CRGBPalette16::CRGBPalette16(const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&, const CRGB&)

     CRGBPalette16( const CRGB& c00,const CRGB& c01,const CRGB& c02,const CRGB& c03,

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:650:5: note:   candidate expects 16 arguments, 9 provided

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:649:5: note: candidate: CRGBPalette16::CRGBPalette16()

     CRGBPalette16() {};

     ^~~~~~~~~~~~~

C:\Users\Emmett\Documents\Arduino\libraries\FastLED\src/colorutils.h:649:5: note:   candidate expects 0 arguments, 9 provided

Using library FastLED at version 3.4.0 in folder: C:\Users\Emmett\Documents\Arduino\libraries\FastLED 

exit status 1

no matching function for call to 'CRGBPalette16::CRGBPalette16(CRGB&, CRGB&, CRGB&, CRGB&, CRGB&, CRGB&, CRGB&, CRGB&, CRGB&)'

Eh nevermind, I figured it out. The Pallette needs 16 entries to function properly. Woulda been nice if that was mentioned in the documentation.

Thanks gfvalvo for pointing out that the complete error message might be of use, I'm so used to it being unintelligible lists of files that I don't look too closely at it.

Glad it worked out.

DangerouslyExplosive:
The Pallette needs 16 entries to function properly. Woulda been nice if that was mentioned in the documentation.

One indication to what was required would have been the name of the class: CRGBPalette16

I got close using the FastLED library,

The 2 main libraries (FastLed & adafruit_neopixel) are different in the way they are setup, but they can do the same thing. The examples that are included are in both cases 'examples' If you want to have a running light with changing color, that means you are combining 2 effects. As long as you are just using 'examples' this may not be exactly what you want.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.