arduino+keypad lcd->menu

i have an arduino + lcd keypad and i want to put a function in a case menu but i dont know how .the function must count how many times i push a button in a period of time.i use pin 2 and 3 for buton.if somebody can help me with the cod.please help me. thanx a good day.

the cod for my menu is:

#include <LiquidCrystal.h>

// Initialize the library with the numbers of the interface pins

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

//States for the menu.

int currentMenuItem = 0;

int lastState = 0;

void setup() {

//Set the characters and column numbers.

lcd.begin(16, 2);

//Print default title.

clearPrintTitle();

}

void loop() {

//Call the main menu.

mainMenu();

}

void mainMenu() {

//State = 0 every loop cycle.

int state = 0;

//Refresh the button pressed.

int x = analogRead (0);

//Set the Row 0, Col 0 position.

lcd.setCursor(0,0);

//Check analog values from LCD Keypad Shield

if (x < 100) {

//Right

} else if (x < 200) {

//Up

state = 1;

} else if (x < 400){

//Down

state = 2;

} else if (x < 600){

//Left

} else if (x < 800){

//Select

state = 3;

}

//If we are out of bounds on th menu then reset it.

if (currentMenuItem < 0 || currentMenuItem > 4) {

currentMenuItem = 0;

}

//If we have changed Index, saves re-draws.

if (state != lastState) {

if (state == 1) {

//If Up

currentMenuItem = currentMenuItem - 1;

displayMenu(currentMenuItem);

} else if (state == 2) {

//If Down

currentMenuItem = currentMenuItem + 1;

displayMenu(currentMenuItem);

} else if (state == 3) {

//If Selected

selectMenu(currentMenuItem);

}

//Save the last State to compare.

lastState = state;

}

//Small delay

delay(5);

}

//Display Menu Option based on Index.

void displayMenu(int x) {

switch (x) {

case 1:

clearPrintTitle();

lcd.print (“->TESTARE BATRANI”);

break;

case 2:

clearPrintTitle();

lcd.print (“->TESTARE TINERI”);

break;

case 3:

clearPrintTitle();

lcd.print (“->TESTARE COPII”);

break;

}

}

//Print a basic header on Row 1.

void clearPrintTitle() {

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“MENU TESTER”);

lcd.setCursor(0,1);

}

//Show the selection on Screen.

void selectMenu(int x) {

switch (x) {

case 1:

clearPrintTitle();

lcd.print (“Selectat TEST BATRANI”);

//Call the function that belongs to Option 1

break;

case 2:

clearPrintTitle();

lcd.print (“Selectat TEST TINERI”);

//Call the function that belongs to Option 2

break;

case 3:

clearPrintTitle();

lcd.print (“Selectat TEST COPII”);

//Call the function that belongs to Option 3

break;

}

}

You’ll get more help if you provide links to the key items. For instance;

http://linksprite.com/wiki/index.php5?t … or_Arduino

If you use the code tags your posted code will be more easily read.

(click to open)

Lastly look at the example code (from the link above) and see how it detects each separate button push by storing which button was pushed on it’s prior loop and comparing that to what’s been read on the present loop.

void loop()
{
   adc_key_in = analogRead(0);    // read the value from the sensor 
   key = get_key(adc_key_in);  // convert into key press
   if (key != oldkey)   // if keypress is detected
   {
     delay(50);  // wait for debounce time
     adc_key_in = analogRead(0);    // read the value from the sensor 
     key = get_key(adc_key_in);    // convert into key press
     if (key != oldkey)    
     {   
       lcd.setCursor(0, 1);
       oldkey = key;
       if (key >=0)
       {
           lcd.print(msgs[key]);              
       }
     }
   }
   delay(100);

All you need to do is add some counter variables in the proper places.

thanks man it will be usefull