#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
char buttons[16] = {
'1','2','3','A',
'4','5','6','B',
'7','8','9','C',
'*','0','#','D'
};
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(13,OUTPUT);
lcd.init();
}
void ResetAll(){
for(int i=2;i<=5;i++){
digitalWrite(i, HIGH);
}
}
bool ReadPulseIO(int output,int input){
ResetAll();
digitalWrite(output, LOW);
return digitalRead(input)==LOW;
}
int ReadNumpadKey(){
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(ReadPulseIO(5-i,9-j))
return i+j*4;
}
}
return -1;
}
bool IsNumpadKeyPressed(int key){
return ReadNumpadKey()==key;
}
bool waiting = true;
void loop() {
// put your main code here, to run repeatedly:
if(ReadNumpadKey()!=-1 ) {
if(waiting) {
lcd.print(buttons[ReadNumpadKey()]);
waiting = false;
}}
else
waiting = true;
}