LCD Increment and Decrement For Display

Thread Starter

ajitnayak

Joined Feb 22, 2013
49
Dear all.
I am trying to call Display menu. If up key is pressed Displayed has to be incremented and stay in particular window if Decremented, go to previous Display function and show previous Display function.
I am using Arduino UNO board and below circuit Setup for reading key



http://www.freetronics.com/pages/16x2-lcd-shield-quickstart-guide#.Uv9jb87pegI

Rich (BB code):
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
static int button_counter=0;
#define btnRIGHT  0        // Okay
#define btnUP     1        // inc
#define btnDOWN   2        // dec
#define btnLEFT   3        // Select
#define btnSELECT 4        // Menu
#define btnNONE   5
#define beeper A1      // Alarm buzzer
#define shortBeep 100
#define longBeep  500

void setup()
{
Serial.begin(9600);
}
void loop()
{
lcd_call();
}

 void lcd_call()
{

 int button = read_LCD_buttons();  



if(button==btnUP)
{
 button_counter=button_counter+1; 
 Serial.print("button_counter");
 Serial.println(button_counter);
}else if(button==btnDOWN)
{
  button_counter=button_counter-1; 
   Serial.println(button_counter);
}

if (button_counter>5)
{
  button_counter=1;
}else

while(button_counter<5)
{
   int button = read_LCD_buttons();  
  if(button != prev_button && button !=  btnNONE)
{
  prev_button = button; 
//timedBeep(shortBeep,2); 
}

if ((((button ==btnUP )||(button_counter==1))||((button ==btnDOWN )))&&(prev_button==btnUP))
{
digitalClockDisplay();//timedBeep(200,1); 

}else if((((button ==btnUP )||(button_counter==2))||((button ==btnDOWN )))&&(prev_button==btnUP))
{
 Display_angle();//timedBeep(200,1); 
}else if((((button ==btnUP )||(button_counter==3))||((button ==btnDOWN )))&&(prev_button==btnUP))
{
Display_coordinate();//timedBeep(200,1); 
}else if((((button ==btnUP )||(button_counter==4))||((button ==btnDOWN )))&&(prev_button==btnUP))
{
  button_loop();//timedBeep(500,4); 
}else if((((button ==btnUP )||(button_counter==5))||((button ==btnDOWN )))&&(prev_button==btnUP))
{
   Display_Wind();//timedBeep(200,1); 
}
  
}
}


void Display_Wind()
{
....Display Wind perameter........
}
void button_loop()
{
.....Button loop selection.........
}
void Display_coordinate()
{
.....Display coordinate.........
}
void  Display_angle()
{
......Display angle........
}
void digitalClockDisplay()
{
.......Display Date and time.........
}

int read_LCD_buttons()
{
  adc_key_in = analogRead(0);      // read the value from the sensor
  // my buttons when read are centered at these valies: 0, 131, 307, 481, 722
  // we add approx 50 to those values and check to see if we are close
  // No button pressed should be 1023
  if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
  if (adc_key_in < 50)   return btnRIGHT; 
  if (adc_key_in < 195)  return btnUP;
  if (adc_key_in < 380)  return btnDOWN;
  if (adc_key_in < 555)  return btnLEFT;
  if (adc_key_in < 790)  return btnSELECT;  
  return btnNONE;  // when all others fail, return this...

}
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
That's some list of conditional statements there. Have you explored all your options to disprove something simpler would work like...

Rich (BB code):
if((((button ==btnUP )||(button_counter==4))||((button ==btnDOWN )))&&(prev_button==btnUP))
{
    button_loop();//timedBeep(500,4); 
}
else
{
    Display_Wind();//timedBeep(200,1); 
}
 
Top