#include <TM1637Display.h>
#include <Keypad.h>
#define CLK 2
#define DIO 3
const byte ROWS = 4; //four IOWS
const byte COLS = 4; //three columns
//define the cymbols on the buttons of the keypads
char keypadArray[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {4, 5, 6, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 9, 10,11}; //connect to the column pinouts of the keypad
//initialize an instance of the Keypad class
Keypad myKeypad = Keypad(makeKeymap(keypadArray), rowPins, colPins, ROWS, COLS);
//create a 7. Segment Display library intance
TM1637Display display (CLK, DIO);
int keyNum = 0;
void setup() {
display.setBrightness(0x0f);
}
void loop() {
char key = myKeypad.getKey();
int num = key - '0';
if (key) {
Serial.print(key);
if (key == '*') {
for (int key=keyNum;key>=0;key--){
display.showNumberDec(key);}
} else {
if(keyNum<=9999){
keyNum = (keyNum*10) + (int(key)-48);
}
}
if (key == '#'){
keyNum =0;
Serial.print(key);
}
}
display.showNumberDec(keyNum,0);
}