First, you should be making an effort to post well formatted code. This means consistent indentation, commenting out comments in the code (e.g. "....Display Wind perameter........"), and making sure you only paste the code and not links and strange characters (forum tags within code seem to inhibit the syntax highlighting).
As posted, your code is extremely difficult to take in visually. Put in the effort to make it more readable if you want better help. This time only, I'll fix it for you so you can see how it should look:
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...
}
Second, it's considered improper to cross-post your question to different forums at the same time. Someone on one forum might spend their time answering your question, without realizing that it might have been already answered elsewhere. This wastes the time and effort of that person, as well as keeping them from helping someone else.
Finally, you should be more clear about your problem. Be more specific when you describe what you're trying to accomplish. Since you sort of told us what you need to do, and provided code you wrote to attempt it, you should also describe exactly what the problem is you're seeing. This is especially important for device-specific code, where most people here do not have the hardware at their disposal.
I've never worked with the Arduino before, but I do have some comments about your code.
I see a few variables being used that have not been declared ("prev_button", "adc_key_in").
In the "lcd_call()" function, you increment "button_counter" when UP is pressed, and decrement it when DOWN is pressed. Then you check if it's greater than five - if so, you reset it to one. But what if it is less than one? You don't seem to take that case into account.
The logic says "if the counter is greater then five, set it to one ... else run your checking loop to determine the display". Why is this an if/else relationship? Shouldn't the checking loop be run regardless? Technically, this seems to happen anyway, since that function is called in a loop of its own. But you should strive for clear logic.
It seems the biggest problem is that your "display update" logic is terribly flawed. Why do you have this logic in a loop? And more importantly, why does it loop "while button_counter is less than five"? You do not change the value of "button_counter" in this loop, so unless there's another mechanism I'm unaware of (e.g. interrupts), the program execution will be stuck there. Sure you check for a button press within the loop, but the counter value will never change.
It seems like the code for the "lcd_call()" function was banged out with little thought. You need to figure out the logic, on paper, before writing it in code. A basic flowchart will help you see the logic you need to implement. Break the problem down into smaller pieces, and tackle them one at a time. Take it step by step. Make sure you understand the flow of logic, and the decisions your logic needs to make. If necessary, translate the flowchart into pseudo-code. Only then should you begin writing code. Start small - for instance, write code to print specific messages when certain buttons are pressed so you know that part is working correctly. Then add some more code to solve the next small problem, and test that. Gradually build your program, testing along the way.