#include <Keypad.h>
#include <SevSeg.h>
// Define pin configuration for keypad
#define ROWS 4
#define COLS 4
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'E', '0', 'F', 'D'}
};
byte rowPins[ROWS] = {PB0, PB1, PB2, PB3}; // Adjust these pins based on your configuration
byte colPins[COLS] = {PB4, PB5, PB6, PB7}; // Adjust these pins based on your configuration
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Define pin configuration for seven-segment display
SevSeg sevseg;
void setup() {
Serial.begin(9600);
// Define pin configuration for seven-segment display
byte segmentPins[] = {1, 2, 3, 4, 5, 6, 7}; // A to G segments
byte digitPins[] = {8}; // Common cathode (CC) pin
sevseg.begin(COMMON_CATHODE, sizeof(digitPins), digitPins, segmentPins);
sevseg.setBrightness(50); // Adjust brightness as needed
}
void displayHexDigit(char hexDigit) {
// Display the hexadecimal digit on the seven-segment display
byte hexIndex;
if (hexDigit >= '0' && hexDigit <= '9') {
hexIndex = hexDigit - '0';
} else if (hexDigit >= 'A' && hexDigit <= 'F') {
hexIndex = hexDigit - 'A' + 10;
} else {
return; // Invalid input, do nothing
}
sevseg.setNumber(hexIndex);
sevseg.refreshDisplay();
delay(500); // Adjust the delay as needed
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.println("BJIRR LAH MUMET " + String(key));
// Display key on seven-segment display
if ((key >= '0' && key <= '9') || (key >= 'A' && key <= 'F')) {
displayHexDigit(key);
}
}
}