Hello, I am trying to make a LCD interface for one of my projects. I am using three pushbuttons, two of them to move a cursor up and down and another will be used to select items. My interface has 8 different pages and all of them are inteconnected as it can be seen in the code in the select() function. However, I am having some troble operating the different pages, moving the cursor is working fine, but the menus 5, 6, and 7 are not even appearing (by that I mean when I select them nothing happens) and in some menus like menu 8 when I press the backwards button ("Voltar") it comesback to menu number 4, instead of 1, and from menu 4 coming back to menu 1 doesn't work, again when I press the backwards cursor nothing happens. If anyone understand the issue and is able to explain I would be very thankful!!!
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int upButton = 4;
int downButton = 3;
int selectButton = 2;
int menu = 1;
int linha = 1;
void setup() {
Serial.begin(9600);
lcd.begin(20, 4);
lcd.backlight();
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
pinMode(selectButton, INPUT_PULLUP);
Umenu();
}
void loop() {
if (!digitalRead(downButton)){
down();
Umenu();
delay(100);
while (!digitalRead(downButton));
}
if (!digitalRead(upButton)){
up();
Umenu();
delay(100);
while(!digitalRead(upButton));
}
if (!digitalRead(selectButton)){
select();
Umenu();
delay(100);
while (!digitalRead(selectButton));
}
Serial.print(linha);
Serial.println(menu);
}
void Umenu(){
lcd.clear();
switch (menu){
case 0:
menu = 1;
break;
case 1:
lcd.setCursor(0, (linha-1));
lcd.print(">");
lcd.setCursor(1, 0);
lcd.print("Status");
lcd.setCursor(1, 1);
lcd.print("Valores");
lcd.setCursor(1, 2);
lcd.print("Configuracoes");
lcd.setCursor(1, 3);
lcd.print("Modo Manual");
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("Sensores:");
lcd.setCursor(0, 1);
lcd.print("Reles:");
lcd.setCursor(0, 2);
lcd.print("Modo sistema:");
lcd.setCursor(0, 3);
lcd.print(">Voltar");
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("Valor 1:");
lcd.setCursor(0, 1);
lcd.print("Valor 2:");
lcd.setCursor(0, 2);
lcd.print(">Voltar");
break;
case 4:
lcd.setCursor(0, (linha-1));
lcd.print(">");
lcd.setCursor(1, 0);
lcd.print("Valor Noite:");
lcd.setCursor(1, 1);
lcd.print("Corelacao sensores:");
lcd.setCursor(1, 2);
lcd.print("Erro:");
lcd.setCursor(1, 3);
lcd.print("Voltar");
break;
case 5:
lcd.setCursor(0, 0);
lcd.print("Valor Noite:");
lcd.setCursor(0, 2);
lcd.print("← + -");
break;
case 6:
lcd.setCursor(0, 0);
lcd.print("Correlacao sensores:");
lcd.setCursor(0, 2);
lcd.print("← + -");
break;
case 7:
lcd.setCursor(0, 0);
lcd.print("Erro:");
lcd.setCursor(0, 2);
lcd.print("← + -");
break;
case 8:
lcd.setCursor(0, (linha-1));
lcd.print(">");
lcd.setCursor(1, 0);
lcd.print("Frente");
lcd.setCursor(1, 1);
lcd.print("Tras");
lcd.setCursor(1, 2);
lcd.print("Liga/Desliga");
lcd.setCursor(1, 3);
lcd.print("Voltar");
break;
case 9:
menu = 8;
break;
}
}
void select(){
switch(menu){
case 1:
switch (linha) {
case 1:
menu = 2;
break;
case 2:
menu = 3;
break;
case 3:
menu = 4;
break;
case 4:
menu = 8;
break;
}
break;
case 2:
menu = 1;
break;
case 3:
menu = 1;
break;
case 4:
switch(linha){
case 1:
menu = 5;
break;
case 2:
menu = 6;
break;
case 3:
menu = 7;
break;
case 4:
menu = 1;
break;
}
case 8:
switch(linha){
case 1:
//adicionar funcao pra mexer para tras
break;
case 2:
//adicionar funcao frente
break;
case 3:
//adicionar funcao liga e desliga
break;
case 4:
menu = 1;
break;
}
case 5:
menu = 4;
break;
case 6:
menu = 4;
break;
case 7:
menu = 4;
break;
}
}
void up(){
switch(menu){
case 1:
linha--;
break;
case 2:
break;
case 3:
break;
case 4:
linha--;
break;
case 5:
//aumentar valor noite
break;
case 6:
//aumentar correlacao de sensor
break;
case 7:
//aumentar erro
break;
case 8:
linha--;
break;
}
if (linha <= 0){
linha=1;
}
else{
}
}
void down(){
switch(menu){
case 1:
linha++;
break;
case 2:
break;
case 3:
break;
case 4:
linha++;
break;
case 5:
//aumentar valor noite
break;
case 6:
//aumentar correlacao de sensor
break;
case 7:
//aumentar erro
break;
case 8:
linha++;
break;
}
if (linha >= 5){
linha = 4;
}
else{
}
}