Hi there, I'm using a web app to set the HSV values of my

Hi there,

I’m using a web app to set the HSV values of my leds using the FastLED library (only Hue actually, Saturation and Brightness are set to 255). Now I want to do a HSV to RGB conversion, so I can use the RGB value for my web app background color or something. How do I do this? Can you point me in the right direction? Using a Particle Photon and Neopixel led ring.

I’ve found the snippet below but I don’t know how to output the actual RGB value so I can send it back:

// HSV (Rainbow) to RGB color conversion
CHSV hsv( 160, 255, 255); // pure blue in HSV Rainbow space
CRGB rgb;
hsv2rgb_rainbow( hsv, rgb);
// rgb will now be (0, 0, 255) – pure blue as RGB

What I have so far:

#include <FastLED.h>
FASTLED_USING_NAMESPACE;

#define NUM_LEDS 16
#define DATA_PIN 2

int led = D7;
int sliderValue;
int j;

void setup()
{
pinMode(led, OUTPUT);
digitalWrite(led, LOW);

leds[i] = CRGB::White; 
FastLED.show();

sliderValue = 20;

}

void loop() {
}

int sliderUpdated(String command) {

j = sliderValue;
    
for (int i=0; i<16; i++){
leds[i] = CHSV( j, 255, 255);
FastLED.show(); 

}

Thank you so much!

@Bram_Hendriks In the process of setting a pixel color using HSV, it is automatically converted to RGB under the hood.

leds[0] = CHSV(42,255,255);

leds[0] now has R,G,B values, just like that! And you can access the values like so:

uint8_t redValue = leds[0].r;
uint8_t greenValue = leds[0].g;
uint8_t blueValue = leds[0].b;

Or, in the case of your example above you could use:

uint8_t redValue = rgb.r;
uint8_t greenValue = rgb.g;
uint8_t blueValue = rgb.b;

Here’s a sketch that prints out values and displays the converted colors on a few pixels.

@marmil Hi Marc, thank you so much, this really helps! The sketch example too! Thanks!