I find pastebin more convenient for long programs than an attached .ino file.
And I have no idea what the problem might be. I note that line 120 has MENU_STATE, DEC which is not the same as line 95
@Mike Mc, you have a long program - when did the problem emerge? Can you reproduce it in a short program? Or has it arisen because the program is long?
I added DEC just to see if it makes any difference. It doesn't.
It is a long program but it is not even 50% of flash so it's not a memory issue as far as I can see.
Not tried reproducing it in a short program but i've never come across this problem before when printing to the serial monitor. Just with this program.
I also find that items printed to the OLED display are also corrupted unless I print the same thing first. it's almost like you have to do something prior to doing it within another function for it to work properly. It's totally bizarre.
O … k. That sort of thing can be caused by code scribbling over memory that it doesn't own. When you remove line 95, it rearranges the layout of what's stored in memory, and suddenly you see the previously hidden bug.
Let's see if we can find it for you. Hmm - here's one:
char myString[9];
if (MENU_STATE == DELAY) strcpy(myString, "DELAY") ;
if (MENU_STATE == SHOTS) strcpy(myString, "EXPOSURES") ;
if (MENU_STATE == LENGTH) strcpy(myString, "LENGTH") ;
if (MENU_STATE == INTERVAL) strcpy(myString, "INTERVAL") ;
"EXPOSURES" is 10 characters long: 9 characters and a trailing '\0' terminator. You are copying it into an array that's only 9 characters long.
Couldn't find any others with a cursory look, but that's one. There may be others. Not sure why you have myString declared all over the shop - why not have a static scrap area myString[100] defined at the top of the code, and everyone use that? Why use myString at all? Main reason for moving strings around like that is if you are storing your text in progmem, which it doesn't seem you are doing.
I suggest:
declare char myString[100]; at the top, get rid of all those little declarations that allocate juuust enough space on the stack, see if that fixes it.
Like I said, the code is only half done so still lots of sorting out to do and tidying up, etc. This is just prototyping.
It looked like it may have been the char array not being long enough that was causing it. I've increased it to 16 and the issue seems to have gone away. Thanks for that.