I’m trying to convert rgb values from a sensor to hsv, so I can better play around with them. I’m trying to use the rgb2hsv_approximate command but I’m not sure how to integrate it with my code.
The commented out CRGB lines are working but not giving me the gradient palette results I want. I’m trying to convert to HSV so I can mess with the colors comfortably but I’m definitely missing something… how do I connect this up?
void SetupGradientPalette()
{
CRGB rgb;
CHSV hsv;
hsv = rgb2hsv_approximate( rgb );
CRGB light = CHSV( HUE + 25, SATURATION - 20, BRIGHTNESS);
CRGB dark = CHSV( HUE, SATURATION - 15, BRIGHTNESS);
CRGB medium = CHSV ( HUE - 25, SATURATION, BRIGHTNESS);
// CRGB light = CRGB (gammatable[(int)r], gammatable[(int)g], gammatable[(int)b]);
// CRGB dark = CRGB ((gammatable[(int)r]+5), (gammatable[(int)g]+1), (gammatable[(int)b]+1));
// CRGB medium = CRGB ((gammatable[(int)r]-5), (gammatable[(int)g]-1), (gammatable[(int)b]-1));
Oh yeah… I’ve dealt with a color sensor. It’s not a linear mapping from readings to LED color. But we’ll get back to that.
Basically, read your sensor values r g and b. Then something like:
CRGB readingsAsRGB(r,g,b);
CHSV readingsAsHSV;
rgb2hsv_approximate( readingsAsRGB, readingsAsHSV);
// now readingsAsHSV should be about right
The thing I mentioned before is real though: you need to adjust your incoming RGB readings before using them as LED colors – probably with some sort of gamma correction. I often try this for starters:
r = dim8_video( r ); // and same for g and b
This often helps adjust from sensor readings to LED color values. Sometimes I actually do the dim8_video thing twice to adjust the readings to LED colors-- but it depends what sensor and so on. Totally subjective.
Also I think you want to decrease BRIGHTNESS for dark, not SATURATION.
Oh so and you can then access the hue sat and val of readingsAsHSV as: readingsAsHSV.hue readingsAsHSV.sat and readingsAsHSV.val.
Got it… thanks so much! Here’s the working code for future reference:
CRGB readingsAsRGB (gammatable[(int)r], gammatable[(int)g], gammatable[(int)b]);
CHSV readingsAsHSV;
readingsAsHSV = rgb2hsv_approximate(readingsAsRGB);
// now readingsAsHSV should be about right
CRGB light = CHSV( readingsAsHSV.hue + 25, readingsAsHSV.sat - 20, readingsAsHSV.val);
CRGB dark = CHSV( readingsAsHSV.hue, readingsAsHSV.sat - 15, readingsAsHSV.val);
CRGB medium = CHSV ( readingsAsHSV.hue - 25, readingsAsHSV.sat, readingsAsHSV.val);
How are you finding the color matching from sensor-read values to LED colors? Close at all?
I’m using the gamma correction code from Adafruit’s chameleon scarf tutorial. It’s pretty good. I can’t seem to get really saturated colors (red comes out sort of pink, etc). But it’s working pretty well. I’ll post some video soon.
Damn I wish I could find the blog post from the girl in the colour stealing dress I met at the burn a few years ago! She had a great schtick with the colour sensor hidden in her glove, coming up to you saying, “I like the colour of your hat… I’m going to… STEAL IT!” at which point her dress would turn the colour of your hat.
Freaked me the hell out, despite having an approximate idea of how it worked from the get-go :-).
That is genuis. I just might steal it. 
Ooooh I love it. Love. It.