TM 1637 with 3x4 Keypad

Basically, using the 4 digit 7 segment TM1637 module and 3*4 matrix keypad.

I want to be able to type numbers on keypad, and the display will showing the number.
When I press *, it should clear the display and # clear the last digit only, like the video below:

Could someone help me to create this code?

The data sheet says that this chip can be used for a 2x8 keyboard. So you'll have to rewire your keypad into say a 2x6 to make it work.

I want to be able to type numbers on keypad like 0000 or any other number that starts with zero with the code below:

#include <Keypad.h>
#include <TM1637Display.h>
#include <Wire.h>

const byte ROWS = 4;
const byte COLS = 3;

char keys[ROWS][COLS] = {
{‘1’, ‘2’, ‘3’},
{‘4’, ‘5’, ‘6’},
{‘7’, ‘8’, ‘9’},
{’*’, ‘0’, ‘#’}

byte rowPins[ROWS] = {8, 7, 6, 5};
byte colPins[COLS] = {4, 3, 2};

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

int keyNum = 0;

const int CLK = 10; //Set the CLK pin connection to the display
const int DIO = 9; //Set the DIO pin connection to the display

TM1637Display display(CLK, DIO); //set up the 4-Digit Display.

void setup()
for(int i = 0; i< 3; i++)
display.setBrightness(5); //set the diplay to maximum brightness


void loop(){
char key = keypad.getKey();
if(key==’’|| key== ‘#’){
keyNum = 0;
keyNum = (keyNum
10) + (int(key)-48);



Any help???

Seems like a long duration project.

If you change the loop() to this:

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

Do the key presses appear in the serial console? Or can your program already write something to the display?

Do you want to add any time constraints, say to clear an abandoned attempt to enter a code?

It is probably easiest to define an array to hold the numbers as they are entered then, at the end, calculate the decimal value.

so far I’ve managed to make it work, but I don’t know why I can’t type a number starting with ZERO (Eg.0123 or 0000) and make it appear on the display.

As far as I can see, that code will only work for 2 digits and you will lose any leading zeros.
Converting the numbers typed in to make up an integer will naturally cut off leading zeros.

This will also fail to show leading zeros:
display.showNumberDec(keyNum) ;

You need the command, for which this is the prototype, where you can set it to show (at least one?) leading zero:

void showNumberDec(int num, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);

example: display.showNumberDec(keyNum, true ) ;

As, I said, the best way is to load the digits into an array as they are entered. You display the array each time a new digit is entered. After the fourth digit has been entered, you complete the calculation if you need the decimal result. But however you do it, you need to know which position the digit the user is entering is in, so you can multiply it by 10, 100 or 1000 as appropriate.

You also should have a timeout in case someone half enters a code and walks away.