progmem dynamic initialization error

I thought I followed the example on the arduino page to make my own code with progmem. But I keep getting the error

error: variable ‘heart’ with dynamic initialization put into program memory area

why is this?
And is the call of show_pixels correct, or should I make it a pointer? If I do that (add * behind uint32_t) I get the error

variable ‘heart’ must be const in order to be put into read-only section by means of ‘attribute((progmem))’

but it is a const, isn’t it???

//#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>

#define NEO_PIN 12
#define NUM_PIX 60
#define LED_PIN 13

#define HOR_MAX 10
#define VERT_MAX 6

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIX, NEO_PIN, NEO_GRB + NEO_KHZ800);

#define  red  pixels.Color(60, 0, 10)
#define blue  pixels.Color(10, 10, 60)
#define green  pixels.Color(10, 60, 10)
#define  white  pixels.Color(60, 60, 60)

#define delay400  400 // delay for 400ms
#define delaytalk  150

const PROGMEM uint32_t heart[NUM_PIX] = {
  0, 0, 0, 0, 0, 0,
  0, red, red, 0, 0, 0,
  red, 0, 0, red, 0, 0,
  red, 0, 0, 0, red, 0,
  0, red, 0, 0, 0, red,
  red, 0, 0, 0, red, 0,
  red, 0, 0, red, 0, 0,
  0, red, red, 0, 0, 0,
  0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0

void setup() {
  pixels.begin(); // This initializes the NeoPixel library.
  digitalWrite(LED_BUILTIN, LOW);

void show_pixels (uint32_t figure[NUM_PIX]) {
  int pix_id;

  for (int i = 0; i < NUM_PIX; i++) {
    pix_id = i;
    pixels.setPixelColor(pix_id, figure[i]);

void loop() {

  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  // line_draw();

  digitalWrite(LED_BUILTIN, HIGH);
  show_pixels (heart);
  digitalWrite(LED_BUILTIN, LOW);

your array is initialed with ‘red’ which is defined as a function call. A function call happens at run-time, not at compile time.

If you look at the function Color() inside Adafruit_NeoPixel.h, you will see that it is just shifting the RGB values into a 32 bit value which you could do directly. That avoids a run-time function call

static uint32_t   Color(uint8_t r, uint8_t g, uint8_t b) {
    return ((uint32_t)r << 16) | ((uint32_t)g <<  8) | b;

Ah, I hadn't realized that...good one :wink:

but now I have the issue it compiles ok but the colors on the leds is all wrong

i changed the definition of red to

#define  red  256

(I know it is not red, just for testing)
But what I get is wrong values and leds even often change color

I guess I have to use pgm_read_word, but can't find a good description of how to use it

found it, needed to use pgm_read_dword_near)

What are you running this on?
You can put stuff in PROGMEM, but for lots of processors the compiler can’t generate the correct code to read from there automatically.
You have to write special code to access PROGMEM using the pgm_read_xxxx_near functions.