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...

}

Login to post a comment...

Michael Johannes Franz 5 years, 1 month ago

Michael Johannes Franz
Any Code? When you change the resistors like here: http://www.dfrobot.com/image/data/DFR0009/LCDKeypad%20Shield%20V1.0%20SCH.pdf You can use this library for Arduino: https://github.com/loelkes/Arduino_LCDKeypad