#include <Keypad.h>
#include <TM1637.h>

const int CLK = 14;
const int DIO = 15;

TM1637 tm(CLK, DIO);

const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4

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

void setup() {
  Serial.begin(9600);
  pinMode(10, OUTPUT);
  tm.init();
  tm.set(BRIGHT_TYPICAL);
}

void loop() {

 int zaehler = 0;

 int eingabefeld[4] = {0};
 int pinfeld[4] = {1, 2, 3, 4};
 int status = 0;

 while (true)
 {  
     int key = (keypad.getKey());
     int keyint = key - 48;
     if (key != NO_KEY)
     {
      Serial.println(keyint);
      Serial.println(zaehler);
      tm.display(1, 5);
      eingabefeld[zaehler] = keyint;
      zaehler++;
     }

     digitalWrite((14 - zaehler), HIGH);
     

    if (zaehler == 4)   
    {
      status = 1;

      for (int i = 0; i < 4; i++)
      {
        if (eingabefeld[i] != pinfeld[i])
        {
          status = 0;
          break;
        }
      }

      if (status == 1)
      {    
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);  
      delay(200);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);  
      delay(200);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);  
      delay(200);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);  
      delay(200);
      }

      eingabefeld[0] = 0;
      eingabefeld[1] = 0;
      eingabefeld[2] = 0;
      eingabefeld[3] = 0;
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      status  = 0;
      zaehler = 0;
    } 
 }
}
4-Digit Display