Arduino 5 Buttons Keypad
5 Buttons on one analog pin for Arduino & Co.
Easy to make keypad for any microkontroller on one analog pin.
My buttons when read are centered at these valies:
0-down,
143-left,
289-up,
482-select,
734-right.
A part of my code:
// define some values used by the buttons
int adc_key_in = 0; // connect to A0
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 750 && adc_key_in > 700) return btnRIGHT;
if (adc_key_in < 330 && adc_key_in > 250) return btnUP;
if (adc_key_in < 50 && adc_key_in >= 0) return btnDOWN;
if (adc_key_in < 200 && adc_key_in > 100) return btnLEFT;
if (adc_key_in < 550 && adc_key_in > 400) return btnSELECT;
return btnNONE; // when all others fail, return this...
}