FastLED and gradient color palettes

Does anybody compile sample from here: link ?

My code:

DEFINE_GRADIENT_PALETTE( my_heatmap_gp ) {
  0,     0,  0,  0,   //black
128,   255,  0,  0,   //red
224,   255,255,  0,   //bright yellow
255,   255,255,255 }; //full white

CRGBPalette16 MyPalette = my_heatmap_gp;

Error message is: 'my_heatmap_gp' was not declared in this scope on the last line.
FastLED version 3.3.3.

What am I doing wrong?

Please post your full sketch.

If possible, you should always post code directly in the forum thread as text using code tags:

  • Do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code. This will make it easier for you to spot bugs and make it easier for us to read.
  • In the Arduino IDE or Arduino Web Editor, click on the window that contains your sketch code.
  • Press “Ctrl + A”. This will select all the text.
  • Press “Ctrl + C”. This will copy the selected text to the clipboard.
  • In a forum reply here, click the “Reply” button.
  • click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the sketch between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.
  • Repeat the above process if your sketch has multiple tabs.

This will make it easy for anyone to look at it, which will increase the likelihood of you getting help.

If the sketch is longer than the 9000 characters maximum allowed by the forum, then it’s OK to add it as an attachment. After clicking the “Reply” button, you will see an “Attachments and other settings” link that will allow you to make the attachment.

When your code requires a library that’s not included with the Arduino IDE please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

Does anybody compile sample from here: link?

My code:

#include <FastLED.h>
#define LED_PIN     8
#define BRIGHTNESS  96
#define CHIPSET    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 16
CRGB leds[NUM_LEDS];


void setup()
{
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
}

void ShowPalette(CRGBPalette16 aPalette)
{
  for ( int i = 0; i < NUM_LEDS; i++)
  {
    leds[i] =  aPalette[i];
  }
  FastLED.show();
  delay(2000);
}

void loop()
{
  CRGBPalette16 MyPalette;

  //FastLED embedded palette
  ShowPalette(LavaColors_p);

  //My palette #1
  fill_solid(MyPalette, NUM_LEDS, CRGB::Black);
  MyPalette[4]  = CRGB::Red;
  MyPalette[8]  = CRGB::Green;
  ShowPalette(MyPalette);


  //My palette #2
  fill_gradient_RGB(MyPalette, NUM_LEDS, CRGB::Red, CRGB::Blue);
  ShowPalette(MyPalette);

  //My palette #3
  fill_rainbow(MyPalette, NUM_LEDS, HUE_RED, 255 / NUM_LEDS); //full rainbow
  ShowPalette(MyPalette);

  //My palette #4
  DEFINE_GRADIENT_PALETTE( my_heatmap_gp ) {
    0,     0,  0,  0,   //black
    128,   255,  0,  0,   //red
    224,   255, 255,  0,  //bright yellow
    255,   255, 255, 255
  }; //full white
  MyPalette = my_heatmap_gp;
  ShowPalette(MyPalette);
}

Error message is: ‘my_heatmap_gp’ was not declared in this scope on the last line.
FastLED version 3.3.3.
See screenshots:



Just for convenience, screenshots are here: link

What am I doing wrong?

Ok, got it.

DEFINE_GRADIENT_PALETTE must be outside of the function declaration, not within, of course.. My fault.

I'm glad to see you found the problem @SergeS. Thanks for taking the time to post an update. Enjoy!

SergeS:
Ok, got it.

DEFINE_GRADIENT_PALETTE must be outside of the function declaration, not within, of course.. My fault.

Awesome! Would you be able to show us the final code? I'm pretty new to this and I'm not sure where DEFINE_GRADIENT_PALETTE would be declared. Thanks

@lakerice This code snippet has to be placed outside of any function.
Look at the example: (taken from GitHub)

DEFINE_GRADIENT_PALETTE(example_gp) {
  0,     0,  0,  0,   //black
128,   255,  0,  0,   //red
224,   255,255,  0,   //bright yellow
255,   255,255,255 }; //full white

CRGBPalette16 myPal = example_gp; 

void setup() {
  // setup stuff
}

void loop () {
  // loop stuff
}