Electronic – Arduino – Multiple button event with lcd shield

arduinolcd

I'd like to detect two buttons being pressed together with the Arduino LCD shield. Does anyone have example code of handling multiple button events? I need an event when both the Up and Down buttons are pressed together for 2 seconds.

The LCD Shield is the 16*2 HD44780 compatible LCD with WHITE characters & BLUE backlight that has 6 buttons. I got it from www.hotsolder.co.uk.

Best Answer

It looks like this shield has 5 buttons attached to different value resistors on a single analogue pin. The sixth button is hardwired to reset. Here's the schematic.

alt text http://www.nuelectronics.com/estore/images/nustore/projects/lcd_schematics.jpg

The sample code has a lookup table to convert the ADC values to keys:

int  adc_key_val[5] ={30, 150, 360, 535, 760 };

If you're lucky, you might be able to spot two keys being pressed at the same time as a unique ADC reading.

Try writing a short sketch to print the ADC value to the serial port, then experiment. See if you can find unique ranges of ADC values representing the key combinations you're interested in.

To detect a press for a length of time, use the Arduino millis() function to record the time then compare. This is very similar to debouncing a button.