I´m building a menu system for a timer I am working on. Its my first proper project and I am trying to do as much of it as I can on my own, but i´m stumped by one particular problem.
What I am trying to is have a main menu with several sub-menus where you change options, etc. So far I have got to the first option ("logs") and while the main menu and sub menu work, the last option in the sub menu ("back") doesn´t work. What it should do when you press SW2 (a push button) is go back to the main menu, but instead it reverts back to the first option in "logs" menu.
Here is the relevant code,
void mainmenu(){
switch (menuLV1){
case 0: //LOGS
LCDmsgNo = 5;
LCD2msgNo = 1;
if (SW1State == LOW && SW2State == HIGH && SW2PrevState == LOW){
logsMenu = 1;
}
break;
case 1: //Settings
LCDmsgNo = 6;
LCD2msgNo = 1;
break;
case 2: //Information
LCDmsgNo = 14;
LCD2msgNo = 1;
break;
case 3: //Advanced Settings
LCDmsgNo = 7;
LCD2msgNo = 1;
break;
}
// Cycle through Menu Options
if (SW1State == HIGH && SW2State == LOW && SW1PrevState == LOW){
menuLV1++;
}
// Loop back to begining of menu
if (securityLvL == 0 && menuLV1 > 2){ //normal user
menuLV1 = 0;
}
if (securityLvL == 1 && menuLV1 > 3){ //Engineer
menuLV1 = 0;
}
////////// LOGS MENU /////////////
if (logsMenu > 0){ // Only Run if logsMenu is Activated
if (logsMenu > 4){ //returns menu cycle back to beginning
logsMenu = 1;
}
switch (logsMenu){
case 1: // Total Credit
LCDmsgNo = 9;
LCD2msgNo = 4;
if (SW1State == HIGH && SW1PrevState == LOW) {
logsMenu ++;
}
break;
case 2: // Credit in Coin Box
LCDmsgNo = 10;
LCD2msgNo = 5;
if (SW1State == HIGH && SW1PrevState == LOW) {
logsMenu ++;
}
break;
case 3: //Total Power Consumption
LCDmsgNo = 11;
LCD2msgNo = 6;
if (SW1State == HIGH && SW1PrevState == LOW) {
logsMenu ++;
}
break;
case 4: //Back
LCDmsgNo = 12;
LCD2msgNo = 1;
if (SW1State == HIGH && SW1PrevState == LOW) {
logsMenu = 1;
}
if (SW2State == HIGH && SW2PrevState == LOW) {
menuLV1 = 1;
logsMenu = 0;
}
break;
}
}
}
I can post the rest of the code if required, but I think the problem lies somewhere here. Either I have misunderstood the use of Switch Case or I´m doing something dumb.
Thanks for any help you can give.