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[]?

Juraj
18.3k4 gold badges31 silver badges49 bronze badges
asked Dec 2, 2018 at 0:55
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

answered Dec 2, 2018 at 6:11
2
  • @bo-thompson, did it help? Commented 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. Commented Dec 9, 2018 at 3:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.