- Fri Oct 06, 2017 9:16 pm
#196448
Hey Guys,
Long time user, but new to the forums
I'm really stumpped on a simple menu im trying to implement.
Basically its a splash screen, you press ENTER and it goes to main 1
Pressing enter again goes to Menu 2
Pressing enter again goes to Menu 3
Anytime you press the cancel button in menu 1-3 it goes to splash screen.
If anyone can help with this code, i'm just not good at looping and button pressing logic
Long time user, but new to the forums
I'm really stumpped on a simple menu im trying to implement.
Basically its a splash screen, you press ENTER and it goes to main 1
Pressing enter again goes to Menu 2
Pressing enter again goes to Menu 3
Anytime you press the cancel button in menu 1-3 it goes to splash screen.
If anyone can help with this code, i'm just not good at looping and button pressing logic
Code: Select all
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int keypad_pin = A1;
int keypad_value = 0;
char btn_push;
==========================================================
char ReadKeypad()
{
/* Keypad button analog Values
up 0
down 178
enter 305
cancel 398
*/
keypad_value = analogRead(keypad_pin);
if(keypad_value < 10)
return 'u';
else if(keypad_value > 10 && keypad_value < 200)
return 'd';
else if(keypad_value > 290 && keypad_value < 320)
return 'e';
else
return 'c';
}
==========================================================
void WaitBtnRelease()
{
while( analogRead(keypad_pin) < 800){}
}
==========================================================
void setup()
{
lcd.begin();
lcd.backlight();
Splashscreen();
delay(1000);
}
==========================================================
void loop() {
btn_push = ReadKeypad();
if(btn_push == 'e')
{
WaitBtnRelease();
Menu_flow();
}
Splashscreen();
delay(100);
}
==========================================================
void Splashscreen()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Press ENTER to Begin");
}
==========================================================
void Menu_flow()
{
while(ReadKeypad()!= 'c') //if you press cancel button anytime (even inside nested menus), it will go back to very beginning
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Menu 1");
if(btn_push == 'e'){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Menu 2");
if(btn_push == 'e'){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Menu 3");
if(btn_push == 'e'){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Menu 4");
delay(5000); // wait 5 seconds then go back to main menu
}
}
}
}
}
==========================================================