Is there an RGB color table/class or something to help with color selection

Status
Not open for further replies.

Gibbedy

Well-known member
Hello,
I have a little christmas tree with ws2811 Leds and using octows2811 library.

I'm thinking I want to be able to program colors by name rather than rgb values.
Like whats in BasicTest.ino but with more colors
Code:
#define RED    0xFF0000
#define GREEN  0x00FF00
#define BLUE   0x0000FF
#define YELLOW 0xFFFF00
#define PINK   0xFF1088
#define ORANGE 0xE05800
#define WHITE  0xFFFFFF

I'm also thinking there might be something already available or some standard set, maybe html colors or something.

Google didn't give me exactly what i'm after.
Something like this where someone else has already done the typing would be good.
HTML:
http://www.rapidtables.com/web/color/html-color-codes.htm

Thanks.
 
Complicating life a fair bit is that the LEDs are non linear. The colour shift from 0 to one is much greater than from fe to ff. So any colour table could either need to be manually crafted by looking at colours or by doing some pretty vigorous gamme correction to the standard numbers.
 
A good formula for gamma-correction is

val = floor(65535.0 * (i / 255.0) ^ 2.2 + 0.5)

where 65535 = number of steps in your PWM, i = input value, 255 = max input value, 2.2 = gamma.

If you want it fast, you can create a const lookup-table (all values but "i" are constant, so for 256 steps, you need 256 entries)

@GremlinWrangler: Isn't the main reason for the non-linearity the human eye ? I may be wrong, but that's what i remember :)
Esp with PWM, there are only two values: LED OFF (0%) or LED ON(100%)
 
Last edited:
@GremlinWrangler: I'd be happy to start with the standard numbers and see/experiment. (i have all year :))
@Frank B: I don't understand that math. Starting with where pwm steps number comes from.
please_explain.jpg

edit: actually starting with floor, but google fixed me up there.
 
@GremlinWrangler: I'd be happy to start with the standard numbers and see/experiment. (i have all year :))
@Frank B: I don't understand that math. Starting with where pwm steps number comes from.

It's not that miportant for a christmas tree - I guess it would be the first christmas tree with gama correction :)
PWM Steps: I 've never used these LEDs. Its the number of different brightness they can display.
Floor is just a math function
 
I have a class I wrote to manage colors - I use it for tft & OLED screens as well as NeoPixels. I find it invaluable, you are welcome to see if it will work for you or not. You can blend colors, map colors as a liner & non-liner functions of X.

Here's the .h file so you can see if it would be a help or not.

Code:
#ifndef colorObj_h
#define colorObj_h

#include "mapper.h"
#include "multiMap.h"
// uncomment for debug stuff.
#define PRINT_COLOR

// Color definitions
#define	BLACK           0x0000
#define	BLUE            0x001F
#define	RED             0xF800
#define	GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0 
#define WHITE           0xFFFF


// mask extremes..
#define OPAQUE       100   // All the new color
#define TRANSPARENT  0     // None of the new color

class colorObj {

public:
  colorObj(byte inRed, byte inGreen, byte inBlue);
  //colorObj(colorObj* inColor);						// Wanted this one, but the compiler mixes it up with color16.
  colorObj(word color16);
  colorObj(void);

  void setColor(byte inRed, byte inGreen, byte inBlue);
  void setColor(word color16);
  void setColor(colorObj* inColor);						// Why doesn't this one get confused? Who knows?
  word getColor16(void);
    
  byte getRed(void);
  byte getGreen(void);
  byte getBlue(void);

  colorObj mixColors(colorObj* mixinColor,byte mixPercent);  // Create a new color by mixing. (Like the old blend)
  void     blend(colorObj* mixinColor,byte mixPercent);      // Just blend with myself.
    
#ifdef PRINT_COLOR    
  void printRGB(void);
#endif

private :
  byte red;
  byte green;
  byte blue;
};

extern colorObj red;
extern colorObj blue;
extern colorObj white;
extern colorObj black;
extern colorObj green;
extern colorObj cyan;
extern colorObj magenta;
extern colorObj yellow;


// ****** colorMapper ******

class colorMapper {

public:
  colorMapper(void);
  colorMapper(colorObj* inStart, colorObj* inEnd);
  colorMapper(word startC16,word endC16);
  ~colorMapper(void);
  
  void setColors(colorObj* inStart, colorObj* inEnd);

  colorObj Map(float percent);

#ifdef PRINT_COLOR
  void     printColors(void);
#endif
  
private :
  mapper* redMapper;
  mapper* greenMapper;
  mapper* blueMapper;
};


// ****** colorMultiMap ******


class colorMultiMap {
    
    public :
    colorMultiMap(void);
    ~colorMultiMap(void);
    
    void      addColor(double inX, colorObj* color);  // At some numeric value we resolve to this color.
    void      clearMap(void);
    colorObj  Map(double inVal);
    
    protected :
    multiMap  redMap;
    multiMap  greenMap;
    multiMap  blueMap;
};


#endif

If it looks like it would help, Her's where it is in my Github : https://github.com/leftCoast/Arduino/tree/master/libraries/LC_baseTools

The bits it depends on will be in the same folder.

-jim lee
 
Thanks Doc. That's the sort of thing I'm after, however I had a quick look at fastled and think they might be even better. I'm hoping I can use fastled for color selection and color transitions and whatever goodies it has been while actually driving the ws2811 with the powerful octows2811.

Does that sound correct?
Thanks.
 
If the question was if you can use fastled with a OCTOWS2811 shield than the answer is: yes.
If you look at the fastled examples in arduino u find one using the octows2811 just make sure you do the include order right. ;)
 
Thanks.
The question can fastled library use the magic of octows2811 library for efficient dma magic.
 
there is a google + comunity for fastLED probably ask there... i don't know the fastled or the octows2811 libary in the details...
 
there is a google + comunity for fastLED probably ask there... i don't know the fastled or the octows2811 libary in the details...

I found my answer in the wiki... sounds like fastled will give me what I'm after.
Making OctoWS2811 faster with FastLED

If you only have 8 lines of leds, and you are using a Teensy 3/3.1, there's a lot of benefit to using OctoWS2811. Wanting to encourage people to get the most benefit of what is available to them, FastLED 3.1 introduces an OctoWS2811 controller. This code preps OctoWS2811's drawing buffer far faster than using setPixel, and gives you the benefit of FastLED's scaling/dithering/color correction code. How much faster? For a 64x8 led setup, 500µs vs. 2ms. You can see this in action in examples/Multiple/OctoWS2811Demo

A comparison of CPU timings, for writing out 512 leds:

512 leds on 8 pins, w/FastLED3.0: 15,360µs or 66fps max
512 leds on 8 pins, w/OctoWS2811 using setPixel: 2000µs or 500fps max
512 leds on 8 pins, w/FastLED3.1 parallel output: 1900µs or 526fps max
512 leds on 8 pins, w/FastLED3.1 feeding OctoWS2811: 500µs or 2000fps max (sadly, WS2811's get unhappy if you go above 400-500fps)
 
Status
Not open for further replies.
Back
Top