I'm having difficulty getting HSV palettes to work.

I’m having difficulty getting HSV palettes to work. The code in this gist produces a solid pink colour. Quite fetching, but not what I was after :-).

Is there a better/easier way of getting a HSVPalette16 containing the whole colour wheel?

I don’t have a setup with me at the moment to run your test code, so I’ll ask, do your print statements give values you’d expect?

Didn’t know that HSV palettes was a thing, however I do get a solid pink colour on APA102’s, and the print statements don’t give what I would expect. That would be:

224 255 255

I think you’re “initializing” the palette values incorrectly. If you print out the contents of RainbowColorsHSV_p, you’ll see that all 16 entries are CHSV(224,255,255) – a lovely shade of pink, as you note.

You can’t say
CHSVPalette16 RainbowColorsHSV_p = ( c1, c2, c3, c4);
because (c1, c2, c3, c4) is an expression that returns just c4, and then all you’re doing is saying
CHSVPalette16 RainbowColorsHSV_p = c4;
which in this case is the pink.

What I think you are heading for is:
CHSVPalette16 RainbowColorsHSV_p( c1, c2, c3, c4);
Note the lack of assignment there. You’re just calling the initializer with four arguments, and that works great (AFAICT).

So that’s the good news - you were trying to do assignment, not initialization. FIxing that makes it work.

Or it would make it work, if there were an eight-argument initializer for CHSVPalette16, which there isn’t.

If you want to initialize a CHSV palette to the rainbow, you can do this:

for( uint8_t j = 0; j < 16; j++) {
uint8_t hue = j * 16;
RainbowColorsHSV_p[ j ] = CHSV( hue, 255, 255);
}

This all help?

“(c1, c2, c3, c4) is an expression that returns just c4”

:flushed:

I tried that on a hunch figuring if it was wrong it wouldn’t compile. Serves me right for attempting to C++…

Thanks for the tip!