LCD menu .....please help

Hello there,

I am working on a project where I need to create a menu system for temperature controller. having 3 keys and a 1602 LCD. three keys will be used. Two for navigation and one for selection of menu. With following menus.

Main Menu:

  1. Set Ref Temp
  2. Set HIGH Temp
  3. Set LOW Temp
  4. Set Hysteresis

Navigation will be made through the two navigation keys, after getting to particular menu item and pressing select button the parameters for that menu can be changed using the same navigation which was previously used, but now to increment and to decrements values of the parameter. after setting the required value of the parameter, once again the select key is pressed to return back to main menu.

My three keys gives following analog values:

key 1 - 271;
key 2 - 525;
key 3 - 773;

I am not using LCD KEYPAD sheild as shown in most of the videos I have been going through. rather I have made it by myself.

Since things should remain simple I first decided not to get into construction menu directly rather only print which key is pressed on the lcd. The code that I used for this is as

#include<LiquidCrystal.h>
LiquidCrystal lcd(0, 1, 2, 3, 4, 5);

void setup()
{
  lcd.begin(16,2);
}

void loop()
{
  lcd.clear();
  lcd.print("Hello there");
  int a = analogRead(A0);

   switch (a)
{
   case 271:
      lcd.clear();
      lcd.print("up");
    break;

   case 525:
      lcd.clear();
      lcd.print("Sel");
   break;

   case 773:
     lcd.clear();
     lcd.print("Down");
   break;
}
delay(250);
 
}

Now, the problem is when the key is pressed the lcd is updated with its respective screen but the lcd gets cleared as soon as the key is released. So, if I am creating menu system this will not work for. What should I do so that if once the lcd is updated it will not get cleared unless some other key is pressed.

Secondly, any help with building menu is also expected.

I have tried omitting lcd.clear() in several places in code but that didn’t worked. I also tried calling other function to print to LCD so that the LCD holds screen unless other key is pressed, but all in vain.
I have been working on this since last four day for almost 12 Hrs a day but couldn’t find any solution. please help.

Thanks in advance.

I have a small library that allows the menu system to be set up and run from PROGMEM. You can find it at GitHub - MajicDesigns/MD_Menu: Menu system for displays with up to 2 lines or load it through the IDE library manager. Examples in there on how to use it.

It is specifically designed for 1 or 2 line displays, LCD module or otherwise.