#include <Keypad.h>
const int SEGMENTOS[] = {2, 3, 4, 5, 6, 30, 31};
const int PULSADORES[] = {10, 11, 12, 13};
const char KEYS[4][4] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
const byte FILA[] = {35,37,39,41};
const byte COLS[] = {43,45,47,49};
Keypad teclado(makeKeymap(KEYS),FILA,COLS, 4, 4);
const int TABLA_SEGMENTOS[] = {
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111, // 9
0b01110111, // A
0b01111100, // b
0b00111001, // C
0b01011110, // d
0b01111001, // E
0b01110001, // F
0b01000000 // ERROR <- TABLA_SEGMENTOS[16]
};
void a7segmentos(int n) {
if (n < 0 or n > 15) {
n = 16; // ERROR
}
for (int i = 0; i < 7; i++) {
digitalWrite(SEGMENTOS[i], bitRead(TABLA_SEGMENTOS[n], i));
}
}
void setup() {
for (auto &pin : SEGMENTOS) {
pinMode(pin, OUTPUT);
}
for (auto &pin : PULSADORES) {
pinMode(pin, INPUT_PULLUP);
}
}
void loop() {
char t = teclado.getKey();
if(t >= '0' and t <= '9') {
a7segmentos(t - '0');
} else if(t >= 'A' and t <= 'D') {
a7segmentos(t - 'A' + 10);
} else if (t == '*' or t == '#') {
a7segmentos(16);
}
}