}
void loop() {
char key = keypad.getKey();
if (key) {
displayCharacter(key);
delay(1000);
clearDisplay();
}
}
void displayCharacter(char ch) {
// Define segment patterns for each digit (0-9)
// Example: Displaying '1'
// A
// F B
// G
// E C
// D
byte patterns[][9] = {
{0, 0, 0, 0, 0, 0, 1, 1}, // 0
{1, 0, 0, 1, 1, 1, 1, 1}, // 1
{0, 0, 1, 0, 0, 1, 0, 1}, // 2
{0, 0, 0, 0, 1, 1, 0, 1}, // 3
{1, 0, 0, 1, 1, 0, 0, 1}, // 4
{0, 1, 0, 0, 1, 0, 0, 1}, // 5
{0, 1, 0, 0, 0, 0, 0, 1}, // 6
{0, 0, 0, 1, 1, 1, 1, 1}, // 7
{0, 0, 0, 0, 0, 0, 0, 1}, // 8
{0, 0, 0, 0, 1, 0, 0, 1}, // 9
{0, 0, 0, 0, 0, 1, 0, 1}, //a
{1, 1, 0, 0, 0, 0, 0, 1}, //b
{0, 1, 1, 0, 0, 0, 1, 1}, //c
{1, 0, 0, 0, 0, 1, 0, 1}, //d
};
if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'D')) {
// Get the digit index (0-9) from the character
int index = (ch <= '9')? (ch - '0') : (ch - 'A' + 10);
// Write the pattern to the segment pins
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPins[i], patterns[index][i]);
}
}
}
void clearDisplay() {
for (int i = 0; i < 8; i++) {
digitalWrite(segmentPins[i], HIGH);
}
}