I want to use a lot of .h/.cpp files to be used by my ino sketch. In one of these .cpp files (and later more) I want to use constant arrays (like lookup tables). To save SRAM I want to use PROGMEM.

What worked before in the Ino sketch is:

const uint8_t _red[]   PROGMEM = { 0, 9, 10, 220, 230, 240, 255 };

But when I put the line above in a .h or .cpp file I get the error:

Par.h:13:25: error: expected initializer before 'PROGMEM'

Should I include something or can't I use PROGMEM in a .h/.cpp file?


I already found the answer.


#include <avr/pgmspace.h>


See also remark of AnT, which is a more generic (and in most cases better solution):

#include "Arduino.h"

(just to help others with the same problem).

  • 1
    ... that is If you have a reason not to include <Arduino.h>. But if you do include <Arduino.h>, then <avr/pgmspace.h> is included with it anyway. – AnT May 10 '19 at 0:55
  • @AnT Thanks for that remark; I added it to the solution (I really thought I tried it before and didn't work, but it does). – Michel Keijzers May 10 '19 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.