#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include<Keypad.h>
char customKey=0;
#include <TM1637Display.h>
//#include <TM1637.h>
#define CLK 3
#define DIO 2
TM1637Display display = TM1637Display(CLK, DIO);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {A15, A14, A13, A12}; //row pinouts of the keypad
byte colPins[COLS] = {A11, A10, A9, A8}; //column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad
int LCDCol = 0;
int LCDRow = 0;
int patch = 1;
boolean result = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(LCDCol, LCDRow);
}
void loop() {
display.setBrightness(3);
char key = customKeypad.getKey();
// if (key != NO_KEY)
// {
// //lcd.setCursor(0,0);
// lcd.println(key);
// Serial.println(key);
// }
if (key)
{
// if(key='#')
// {
if (key=='1' || key=='2' || key=='3' || key=='4' || key=='5' || key=='6' || key=='7' || key=='8' || key=='9' || key=='0')
{
// if(customKey<3)
// {
Serial.println(key);
// if ( LCDCol > 15 )
// {
// ++LCDRow;
// if (LCDRow>1)
// { LCDRow=0; LCDCol = 0 ; lcd.clear(); }
// LCDCol = 0 ;
// }
lcd.setCursor (LCDCol, LCDRow);
//lcd.setCursor (1,0);
lcd.print(key);
//display.showNumberDec(key);
//key=key++;
//patch=key;
LCDCol++;
//patch;
// if(LCDCol>3)
// {
// LCDCol = 1;
// }
//}
// if(LCDCol>4)
// {
// lcd.setCursor (4,1);
// lcd.print(" ");
// //key='#';
// //while(1);
// }
// if(key>444)
// {
// lcd.setCursor (LCDCol, LCDRow);
// // key=444;
// // patch=444;
// // lcd.setCursor (1,1);
// // lcd.print("44");
// lcd.setCursor (3,1);
// lcd.print(" ");
// }
}
//}
}
if(key=='#')
{
lcd.setCursor (11,1);
LCDCol;
lcd.print(LCDCol);
// result = true;
}
// if(LCDCol>3)
// {
// LCDCol = 1;
// }
if(key=='B')
{
if (key > 0)
// if(LCDCol>0)
{
LCDCol--;
lcd.setCursor(LCDCol, 1);
lcd.print(' '); // Replace it with a blank
}
if (LCDCol < 1) // it keeps cursor to (1,1) position always
{
LCDCol = 1;
}
// if (LCDCol >3)
// {
// LCDCol = 1;
// }
}
// if(key=='B')
// {
// if(LCDCol>1)
// {
// --LCDCol;
// lcd.setCursor (2, 1);
// lcd.print(" ");
// }
// if(LCDCol>2)
// {
// --LCDCol;
// lcd.setCursor (3, 1);
// lcd.print(" ");
// }
// }
// if (LCDCol > 3)
// {
// LCDCol = 1;
// }
if(key=='*')
{
lcd.setCursor (1,1);
lcd.print(" ");
delay(4);
lcd.setCursor (LCDCol, LCDRow);
// if (LCDCol < 1) // it keeps cursor to (1,1) position always
// {
LCDCol = 1;
// }
}
if(key == 'C')
{
if(patch<444)
{
patch=patch+1;
}
else
{
patch=1;
}
//delay(150);
}
else if(key == 'D')
{
if(patch>1)
{
patch=patch-1;
}
else
{
patch=444;
}
//delay(150);
}
//}
if(patch == 1)
{
display.showNumberDec(1);
}
if(patch == 2)
{
display.showNumberDec(2);
}
if(patch == 3)
{
display.showNumberDec(3);
}
if(patch == 4)
{
display.showNumberDec(4);
}
if(patch == 444)
{
display.showNumberDec(444);
}
}