#include <Keypad.h>
/* Display */
/* Keypad setup */
byte rowPins[4] = {5, 4, 3, 2};
byte colPins[4] = {A3, A2, A1, A0};
char keys[4][4] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, 4, 4);
const int segmentPins[] = {10, 9, 6, 7, 8, 11, 12}; // Replace with your segment pins
void setup() {
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT); // Set segment pins as outputs
}
}
void displayDigit(int digit) {
const int digitValues[] = {
0b0111111, // 0
0b0000110, // 1
0b1011011, // 2
0b1001111, // 3
0b1100110, // 4
0b1101101, // 5
0b1111101, // 6
0b0000111, // 7
0b1111111, // 8
0b1101111 // 9
};
// Set the segments to display the digit
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPins[i], (digitValues[digit] >> i) & 1);
}
}
int hexCharToDecimal(char hexChar) {
// Check if the input is a valid hexadecimal character
if (!isxdigit(hexChar)) {
Serial.println("Not a valid key");
return -1; // Return an error code
}
// Convert the hexadecimal character to decimal
if (isdigit(hexChar)) {
return hexChar - '0';
} else {
return toupper(hexChar) - 'A' + 10;
}
}
void loop() {
char key = keypad.getKey();
if (key) {
displayDigit(hexCharToDecimal(key));
Serial.println(key);
}
}