#include <LiquidCrystal.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
const byte ROWS = 4;
const byte COLS = 4;
int digit[ROWS][COLS]={
{1, 2, 3, 12},
{4, 5, 6, 13},
{7, 8, 9, 14},
{10, 0, 11, 15}
};
byte rowPins[] = {9, 8, 7, 6};
byte colPins[] = {5, 4, 3, 2};
int getDigit(){
for (int c = 0; c < COLS; c++){
digitalWrite(colPins[c], LOW);
delay(1);
for (int r = 0; r < ROWS; r++){
if (digitalRead(rowPins[r]) == 0){
while (digitalRead(rowPins[r]) == 0);
return digit[r][c];
}
}
digitalWrite(colPins[c], HIGH);
delay(1);
}
return -1;
}
void setup() {
lcd.begin(16,2);
for (int c = 0; c < COLS; c++){
pinMode(colPins[c], OUTPUT);
}
for (int r = 0; r < ROWS; r++){
pinMode(rowPins[r], INPUT_PULLUP);
}
}
void loop() {
int a = getDigit();
if (a != -1){
lcd.print(a);
}
}