uint8_t code[] = {63, 6, 91, 79, 102, 109, 125, 39, 127, 111};
// Символи: "0","1","2","3","4","5","6","7","8","9"
uint8_t segmPin[] = {2, 3, 4, 5, 6, 7, 8, 9};
// Порти сегментів: A, B, C, D, E, F, G
uint8_t groupPin[] = {19, 18, 17, 20};
//БАХ
uint8_t boom[] = {125, 119, 118};
byte colPort[] = {A11, A10, A9};
byte rowPort[] = {A15, A14, A13, A12};
char keys[4][3] = {{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
void setup() {
for (uint8_t s = 0; s < 7; s++) {
pinMode(segmPin[s], OUTPUT);
}
for (uint8_t group = 0; group < 4; group++)
pinMode(groupPin[group], OUTPUT);
for (uint8_t col = 0; col < 4; col++)
pinMode(colPort[col], INPUT);
for (uint8_t row = 0; row < 4; row++)
pinMode(rowPort[row], INPUT_PULLUP);
}
void loop() {
char key = getKey();
uint8_t displayValue[] = {key - '0',key - '0',key - '0',key - '0'};
displayArray(displayValue);
}
void show_segments(uint8_t num) {
digitalWrite(segmPin[num], HIGH);
}
void show(uint8_t num) {
for (uint8_t s = 0; s < 7; s++) {
uint8_t segmState = bitRead(code[num], s);
digitalWrite(segmPin[s], segmState);
}
}
void setGroup(uint8_t newGroup) {
for (uint8_t group = 0; group < 4; group++) {
if (group == newGroup)
digitalWrite(groupPin[group], LOW);
else
digitalWrite(groupPin[group], HIGH);
}
}
void displayArray(uint8_t displayValue[]) {
for (uint8_t group = 0; group < 4; group++) {
clearSegments();
setGroup(group);
show(displayValue[group]);
delay(1);
}
}
void clearSegments() {
for (uint8_t segm = 0; segm < 7; segm++) {
digitalWrite(segmPin[segm], LOW);
}
}
void setCol(uint8_t newCol) {
for (uint8_t col = 0; col < 4; col++) {
pinMode(colPort[col], INPUT);
}
pinMode(colPort[newCol], OUTPUT);
digitalWrite(colPort[newCol], LOW);
}
char getKey() {
for (uint8_t col = 0; col < 3; col++) {
setCol(col); // Активуємо стовпчик
delay(1); // Затримка на перехідні процеси
for (uint8_t row = 0; row < 4; row++) {
if (digitalRead(rowPort[row]) == LOW)
return keys[row][col];
}
}
return 0;
}