// Includes
#include <Keypad.h>
#include "TM1637TinyDisplay.h"

const uint8_t CLK = A0;
const uint8_t DIO = A1;
TM1637TinyDisplay display(CLK, DIO);

const uint8_t NB7SEG = 4;
char message[NB7SEG + 1];
uint8_t messagePos = 0;

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

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

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

void setup() {
  for (uint8_t i = 0; i < NB7SEG; i++) message[i] = ' ';
  message[NB7SEG] = '\0';
  Serial.begin(115200);
  display.begin();
}

void loop() {
  char key = keypad.getKey();

  if (key != NO_KEY) {
    for (uint8_t i = 0; i < NB7SEG-1; i++) message[i] = message[i + 1];
    message[NB7SEG - 1] = key;
    display.showString(message);
    Serial.println(message);
  }
}
4-Digit Display