       buffer = "";
     }
   } else if (state == INVALID_PIN) {
-    if (timeoutExpired()) {
+    char key = keypad.getKey();
+    if (key) {
+      setState(PIN_ENTRY);
+      buffer = key;
+      updateDisplay();
+    } else if (timeoutExpired()) {
       setState(LOCKED);
     }
   } else {

String buffer = "";

void updateDisplay() {
  if (state == LOCKED) {
    Serial.println("+--------------------+");
    Serial.println("|                    |");
    Serial.println("| Hello Stranger!    |");
    Serial.println("|   Door is locked.  |");
    Serial.println("|                    |");
    Serial.println("+--------------------+");
  } else if (state == PIN_ENTRY) {
    Serial.println("+--------------------+");
    Serial.println("|Entry token read.   |");
    Serial.println("|Please enter PIN:   |");
    Serial.print("| ");


Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#include <LiquidCrystal.h>
LiquidCrystal lcd(A4, A5, A0, A1, A2, A3);

States state = LOCKED;
long timeout_start = 0;
long timeout = 10000;
