Go Down

Topic: LCD and "menu" select (Read 1 time) previous topic - next topic

DeusExMachina

Hi all, new to coding and I'm working with the Uno R3 and the 16x2 LCD shield and their associated libraries.  I have the desired effect working somewhat with the code below using Switch/Case.  However, this only works while the button is held down = digital pin is high.  While held down the sensor values are updating.   Once you let go, the lcd.print value stays on the LCD, but the values go to some default fixed value to display.  I've tried if/else and that didn't work.  Can someone point me to a tutorial to learn how to setup menus and selecting code via inputs such as digital switches?


Code: [Select]
switch (lcd_key)               // depending on which button was pushed, we perform an action
{
   
   case btnRIGHT:
     
     {

       lcd.setCursor(0,1);
     lcd.print("PSI      ");

     lcd.setCursor(9,1);
      lcd.print(sensorValue*(14.7/1023.0));
      break;
     }
   
   case btnLEFT:
     {
       lcd.setCursor(0,1);
     lcd.print("BAR    ");
     lcd.setCursor(9,1);
      lcd.print(sensorValue*(1.0/1023.0));
      break;
     
     }
   case btnUP:
     {
       lcd.setCursor(0,1);
     lcd.print("KPA     ");
     lcd.setCursor(9,1);
      lcd.print(sensorValue*(100.0/1023.0));
      break;
     
     }


crashoverride61088

Howdy,

     I've found a useful library called MenuBackend. Take a look at the discussion http://forum.arduino.cc/index.php?topic=38053.45.

     Another user took this library, and simplified it's usage down to 4 buttons. His tutorial really helped me to understand the logic.
http://www.coagula.org/content/pages/tutorial-manage-menu-and-lcd-display-arduino

     Between his tutorial and the libraries' example code, I worked on a menu for my automated pet feeder menu. I've included the the code here as another example to wrap your brain around it. I only use 3 buttons (next, enter, and escape) and one 16x2 LCD.

     Right now I'm going to go start another post, because the code as written, the debounce means you need to hold the button down for 500ms before it recognizes the push.

     My Code:
https://github.com/dorfman2/auto-pet-feeder.git

     Download for the Menubackend Library:
http://www.arduino.cc/playground/uploads/Profiles/MenuBackend_1-4.zip

crashoverride61088


Have a look here:

http://liudr.wordpress.com/libraries/phi_prompt/


I had a similar issue as the original poster, so I looked at your link. However, it took me a bit of playing around with your code to realize it was hardware-specific. THEN I found your website. Really solid stuff!

Go Up