I'm trying to make a multidimensional character array to hold menu strings in an LCD project.
The idea is that I have a maximum of MAX menu items. Every menu item has ROW rows. Every row contains a maximum of CHAR characters. After reading for a bit, I found out that 2D arrays need to be declared via a pointer. The problem is that it doesn't work for a 3D array!
The following code displays empty lines, but I cannot find my mistake.
#define CHAR 16 //Number of characters per LCD line
#define MAX 100 //Max number of menu items
#define ROW 2 //Number of LCD rows
char firstrun[MAX][ROW][CHAR]=
{ { "This is menu 01", "This is menu 02" },
{ "This is menu 11", "This is menu 12" } };
void setup()
{
Serial.begin(9600);
}
void loop()
{
while(Serial.available()==0){}
int i=Serial.read()-'0';
lcdWrite(firstrun[i][0], firstrun[i][1]);
}
//commented some lines out for debugging via serial monitor
void lcdWrite(char line1[], char line2[])
{
//lcdPosition(0,0);
Serial.println(line1);
//lcdPosition(1,0);
Serial.println(line2);
return;
}
Apparantly, the code works fine if I use char firstrun[][ROW][CHAR] instead of char firstrun[MAX][ROW][CHAR]. Probably because of the memory limitation. Thanks!
Apparantly, the code works fine if I use char firstrun[][ROW][CHAR] instead of char firstrun[MAX][ROW][CHAR]. Probably because of the memory limitation. Thanks!
The [] on the first declaration tells the compiler to count the initializers. Since you are only providing 2, not 100, the array only takes 2 * 2 * 16 bytes, or 64 bytes. Much less than the 3200 that the [MAX] version needs.
PaulS:
The [] on the first declaration tells the compiler to count the initializers. Since you are only providing 2, not 100, the array only takes 2 * 2 * 16 bytes, or 64 bytes. Much less than the 3200 that the [MAX] version needs.
Interesting! That's actually ideal, because the array won't be changed, ever (once the code is final) Thanks again!