1

I'm working on a project for the arduino uno for which I need multiple constant arrays of bytes. Such an array is initialized like so:

const byte charR[] PROGMEM = {
  B01111111,//top half
  B01111111,
  B01000100,
  B01000110,
  B01101111,
  B00111001,
  B00000000,
  B01111000,//bottom half
  B01111000,
  B00000000,
  B00000000,
  B01111000,
  B01111000,
  B00000000
};

This array represents the capital letter R. I read the nth byte of this array like so:

nth_byte = pgm_read_word(charR+n);

This is all fine and good so far, but now I need to take it a step further. I need to create the array message[]. I need to use message[] to read byte arrays in a certain sequence. For instance:

message[] = {
  charR,
  chare,
  charp,
  charl,
  chary,
  charspace,
  charp,
  charl,
  chare,
  chara,
  chars,
  chare
};

Each entry in message[] refers to a byte array that represents a character. Notice how multiples appear. This is kind of like a 2-D array, but I want to save progmem by only defining each character once.

How do I properly initialize message[]? Will I need to use pointers for this? How do I properly get the array size or yth byte of the xth entry in message[]?

0

1 Answer 1

2

const byte* const message[] PROGMEM =

to use an item, load it in RAM

strcpy_P(buffer, (byte*)pgm_read_word(&(message[i])));

source Arduino reference - PROGMEM

2
  • @bo-thompson, did it help?
    – Juraj
    Dec 7, 2018 at 18:24
  • Sorry for the delay, I've been separated from the microcontroller running this project for the last week. Hopefully I will return to it in the coming week and I will mark this as an answer as soon as I've verified that I can understand and use it. Dec 9, 2018 at 3:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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