

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include <Keypad.h> const byte ROWS = 4, COLS = 4; char keys[ROWS][COLS] = { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; byte rowPins[ROWS] = {5, 4, 3, 2}; byte colPins[COLS] = {6, 7, 8, 9}; Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); int segPins[7] = {10, 11, 12, 13, A1, A3, A2}; byte segmentDigits[14][7] = { {1, 1, 1, 1, 1, 1, 0}, // 0 {0, 1, 1, 0, 0, 0, 0}, // 1 {1, 1, 0, 1, 1, 0, 1}, // 2 {1, 1, 1, 1, 0, 0, 1}, // 3 {0, 1, 1, 0, 0, 1, 1}, // 4 {1, 0, 1, 1, 0, 1, 1}, // 5 {1, 0, 1, 1, 1, 1, 1}, // 6 {1, 1, 1, 0, 0, 0, 0}, // 7 {1, 1, 1, 1, 1, 1, 1}, // 8 {1, 1, 1, 0, 0, 1, 1}, // 9 {1, 1, 1, 0, 1, 1, 1}, // A {0, 0, 1, 1, 1, 1, 1}, // b {1, 0, 0, 1, 1, 1, 0}, // C {0, 1, 1, 1, 1, 0, 1} // d }; void setup() { for (int i = 0; i < 7; i++) { pinMode(segPins[i], OUTPUT); digitalWrite(segPins[i], LOW); // Ensure all segments start off } } void displayDigit(int index) { for (int i = 0; i < 7; i++) { digitalWrite(segPins[i], segmentDigits[index][i]); } } void loop() { char key = keypad.getKey();
if (key) { int index = -1; if (key >= '0' && key <= '9') { index = key - '0'; // Numeric keys (0-9) } else if (key >= 'A' && key <= 'D') { index = 10 + (key - 'A'); // Alphabetic keys (A-D) } if (index != -1) { displayDigit(index); // Display valid input } } }