I believe I'm storing the character arrays properly but, as a threat to all you, I will revert to use of strings! if I can't figure this out. Main[0] just draws "01234567". Additionally the line break and dashes are omitted to serial terminal. This is the beginnings of a menu system divied out to a 16x2 LCD, right now it's going to serial term. I haven't done 2D arrays before and don't know a pointer from a straight stick, but fear I may need to use one or the other.
menuIndex is a global int. menuM is being called from main loop which just contains some code for temp sensing and cap touch decoding.
void menuM() {
menuIndex = 1;
char mainM[3][16] = { {"Time Settings"}, {"Lock On/Off"}, {"Schedule Settings"} };
char timeM[2][16] = { {"Time Set"}, {"Temp/Fan Timeouts"} };
char scheduleM[2][16] = { {"Set # of blocks"}, {"Set block X time"} };
char fanM[3][16] = { {"On with H/C"}, {"On all time"}, {"On every"}};
Serial.println(mainM[menuIndex]);
Serial.println(mainM[menuIndex + 1]);
Serial.println("----------");
}
"Schedule Settings" requires 18 bytes. There are other errors.
True. The problem persists.
The problem persists.
Have you fixed the error I pointed out, as well as the others? If so, post the revised code.
Did you remember that array indices begin with zero?
Note: most people add the keyword "static" for local variables (such as mainM[][]) that are to be retained between function calls. It could be that the compiler does this for you, but I don't know.
UPDATE: This code works, I hadn't been calling the function as I inadvertently deleted the call.
I did know that it was a zero-index object. Sadly I can't refrerence the char strings. I did for a short time and forgot and changed something seemingly trivial. All I know is then I got the "01234567" and the char array snippet I called.
void menuM() {
menuIndex = 0;
char mainM[3][20] = { {"Time Settings"}, {"Lock On/Off"}, {"Schedule Settings"} };
char timeM[2][20] = { {"Time Set"}, {"Temp/Fan Timeouts"} };
char scheduleM[2][20] = { {"Set # of blocks"}, {"Set block X time"} };
char fanM[3][20] = { {"On with H/C"}, {"On all time"}, {"On every"}};
Serial.println(mainM[menuIndex]);
Serial.println(mainM[menuIndex + 1]);
Serial.println("----------");
}
This code:
int menuIndex;
void setup() {
Serial.begin(9600);
menuM();
}
void loop() {}
void menuM() {
menuIndex = 0;
char mainM[3][20] = { {"Time Settings"}, {"Lock On/Off"}, {"Schedule Settings"} };
char timeM[2][20] = { {"Time Set"}, {"Temp/Fan Timeouts"} };
char scheduleM[2][20] = { {"Set # of blocks"}, {"Set block X time"} };
char fanM[3][20] = { {"On with H/C"}, {"On all time"}, {"On every"}};
Serial.println(mainM[menuIndex]);
Serial.println(mainM[menuIndex + 1]);
Serial.println("----------");
}
prints:
Time Settings
Lock On/Off
----------
Thanks, I got it working!