How do I go about passing a palette into a function?

fastled-support
gplus
(Garrison Burger) #1

How do I go about passing a palette into a function?
nblendPaletteTowardPalette is a good example of the type of function I want to write, and it looks like you use CRGBPalette& to get an input palette. However no matter what I do I just get the error: “variable or field ‘xxxx’ declared void”

Edit: better explanation from my comment below

I want a function such as:
void hsv2rgbPalette(CRGBPalette& rgb, CHSVPalette& hsv)
This seems to be the correct way to pass a palette to a function to read/edit it (based on how nBlendPaletteTowardsPalette works), but it only gives the error: “variable or field ‘hsv2rgbPalette’ declared void”. Thought it might be because I need a prototype in a header but that doesn’t work either.

(Ken White) #2

@Garrison_Burger - You should looked at @Mark_Kriegsman "s PaletteCrossfade.ino at:

This will help you understand nblendPaletteTowardPalette.

Also, you should post your code in GitHub Gist and put a link to that code here so that you can get help to make it work correctly.

(Garrison Burger) #3

@Ken_White I understand how nBlendPaletteTowardsPalette works. I’m trying to make a new function that takes palettes as an input and can change them.

nBlendPaletteTowardsPalette takes the current palette and target palette and changes the current one to be closer. I want to make a function that converts an HSV palette to an RGB palette in a special way. So I need to pass a CRGBPalette16 and CHSVPalette16 to the function to read and edit them.

The definition of nBlendPaletteTowardsPalette is:
void nblendPaletteTowardPalette( CRGBPalette16& current, CRGBPalette16& target, uint8_t maxChanges)

I want a function such as:
void hsv2rgbPalette(CRGBPalette& rgb, CHSVPalette& hsv)
This seems to be the correct way to pass a palette to a function to read/edit it (based on how nBlendPaletteTowardsPalette works), but it only gives the error: “variable or field ‘hsv2rgbPalette’ declared void”. Thought it might be because I need a prototype in a header but that doesn’t work either.

(Ken White) #4

@Garrison_Burger - You might want to try the following way to pass palettes to a function instead of what you have posted:

void hsv2rgbPalette(CRGBPalette16 rgb, CHSVPalette16 hsv){//stuff};

This compiles in a sketch using the latest version of FastLED and the Arduino IDE 1.8.7.

(Garrison Burger) #5

@Ken_White this fails in the same way. It just won’t accept that those palettes are valid types:

error: variable or field ‘hsv2rgbPalette’ declared void
void hsv2rgbPalette(CRGBPalette16 rgb, CHSVPalette16 hsv) {
error: ‘CRGBPalette16’ was not declared in this scope
error: ‘CHSVPalette16’ was not declared in this scope
void hsv2rgbPalette(CRGBPalette16 rgb, CHSVPalette16 hsv) {

This is on FastLED 3.2.1 and Arduino 1.8.8. Same error with Arduino 1.8.7 as well

(Ken White) #6

@Garrison_Burger - Can you please put your sketch in Gist and publish a link to the code here or can you please post the whole hsv2rgbPalette function code here? It is extremely difficult to help you without see all or enough of the pieces of the puzzle. Something in the function might be causing your problems.