const int SEGMENTOS[] = {2, 3, 4, 5, 6, 30, 31};
const int PULSADORES[] = {10, 11, 12, 13};
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() {
int n = 0;
int pot2 = 1;
for (auto &pul : PULSADORES) {
n += (not digitalRead(pul)) * pot2;
pot2 *= 2;
}
a7segmentos(n);
}