it depends for what the data is needed and how it should be used. When @Prasanjith will explain the usecase in more detail there might be another solution.
however, 3 sketches to compare:
//Sketch uses 1774 bytes (5%) of program storage space. Maximum is 32256 bytes.
//Global variables use 278 bytes (8%) of dynamic memory, leaving 1864 bytes for local variables. Maximum is 2048 bytes.
byte Pat2[5][18] = {
{0, 1, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2},
{0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0},
{0, 0, 3, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0},
{4, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 4},
{0, 0, 0, 5, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 5, 0}
};
void readData()
{
for (int x = 0; x < 5; x++)
for (int y = 0; y < 18; y++)
Serial.println(Pat2[x][y]);
}
void setup() {
Serial.begin(115200);
readData();
}
void loop() {
}
PROGMEM
/*
PROGMEM
Sketch uses 1774 bytes (5%) of program storage space. Maximum is 32256 bytes.
Global variables use 188 bytes (9%) of dynamic memory, leaving 1860 bytes for local variables. Maximum is 2048 bytes.
*/
const byte Pat3[5][18] PROGMEM = {
{0, 1, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2},
{0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0},
{0, 0, 3, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0},
{4, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 4},
{0, 0, 0, 5, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 5, 0}
};
void readData()
{
for (int x = 0; x < 5; x++)
for (int y = 0; y < 18; y++)
Serial.println(pgm_read_byte(&Pat3[x][y]));
}
void setup() {
Serial.begin(115200);
readData();
}
void loop() {
}
smaller Array:
/*
small in RAM
Sketch uses 1754 bytes (5%) of program storage space. Maximum is 32256 bytes.
Global variables use 218 bytes (10%) of dynamic memory, leaving 1830 bytes for local variables. Maximum is 2048 bytes.
*/
struct MyStruct
{
byte row: 3;
byte col: 5;
byte value;
};
MyStruct pat4[] = {
{0, 1, 1},
{0, 4, 3},
{0, 17, 2},
{1, 3, 2},
{1, 7, 2},
{1, 11, 2},
{1, 16, 2},
{2, 2, 3},
{2, 5, 3},
{2, 12, 3},
{3, 0, 4},
{3, 8, 4},
{4, 3, 5},
{4, 9, 5},
{4, 16, 5}
};
void readData()
{
size_t index = 0;
for (int x = 0; x < 5; x++)
for (int y = 0; y < 18; y++)
{
byte actual = 0;
if (x == pat4[index].row && y == pat4[index].col)
{
actual = pat4[index].value;
index++;
}
Serial.println(actual);
}
}
void setup() {
Serial.begin(115200);
readData();
}
void loop() {
}