I need to create a circuit that when I press a key on the matrix keyboard, it is shown on the 7-segment display. I managed to structure the code. But it goes into an infinite loop or ends up not showing the number on the Display. Could you guys help me?
The code is below
#include <Keypad.h>
const int pins[7] = {10,A0,A1,A2,A3,A4,A5};
byte byteNumbers[10][7] = {
{1,1,1,1,1,1,0},
{0,1,1,0,0,0,0},
{1,1,0,1,1,0,1},
{1,1,1,1,0,0,1},
{0,1,1,0,0,1,1},
{1,0,1,1,0,1,1},
{1,0,1,1,1,1,1},
{1,1,1,0,0,0,0},
{1,1,1,1,1,1,1},
{1,1,1,1,0,1,1}
};
char display;
int digit;
void turnOn(int number){
for(int i = 0; i <= 6; ++i){
digitalWrite(pins[i], byteNumbers[number][i]);
}
}
const byte Rows = 4;
const byte Cols = 4;
char rowsCols[Rows][Cols] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[Rows] = {9, 8, 7, 6};
byte colPins[Cols] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(rowsCols), rowPins, colPins, Rows, Cols);
void setup(){
Serial.begin(9600);
for(int i = 0; i <= 6; i++){
pinMode(pins[i], OUTPUT);
}
for(int i = 2; i <= 9; i++){
pinMode(i, OUTPUT);
}
}
void loop(){
display = customKeypad.getKey();
digit = display - '0';
turnOn(digit);
if(display){
Serial.println(display);
}
}
I think the problem is in the loop function.
Thanks in advance.