Good afternoon, I am making a 4x3 keypad for an access control system. The problem I have is that when I press a key for the first time on the keypad, the key pressed is displayed correctly in serial, but if I press another key it is not displayed. Am I missing something in the circuit? Is there something missing in my programming? I appreciate your help, thank you.
const char keys[4][3] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
const byte rowPins[4] = {13, 12, 11, 10};
const byte colPins[3] = {9, 8, 7};
byte i, j;
void setup(){
for (i=0; i<4; i++){
pinMode(rowPins[i], OUTPUT);
}
for (i=0; i<3; i++){
pinMode(colPins[i], INPUT_PULLUP);
}
Serial.begin(9600);
}
void loop(){
for (i=0; i<4; i++){
digitalWrite(rowPins[i], LOW);
for (j=0; j<3; j++) {
if (!digitalRead(colPins[j])){
Serial.print("Key: ");
Serial.println(keys[i][j]);
while(digitalRead(!colPins[j]));
}
}
digitalWrite(rowPins[i], HIGH);
}
delay(10);
}