#define LCD_LEN 16
#define LCD_WID 2
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,LCD_LEN,LCD_WID);
#include <Keypad.h>
const uint8_t ROWS = 3;
const uint8_t COLS = 3;
char keys[ROWS][COLS] = {
{ '1', '2', '3' },
{ '4', '5', '6' },
{ '7', '8', '9' },
};
uint8_t colPins[COLS] = { 10, 9, 8 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 13, 12, 11 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
char name[8]{'Y','a','r','o','s','l','a','v'};
char age[] = "21";
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
}
// void loop()
// {
// for(int i=-5;i<5;i++)
// {
// move(i);
// }
// // Serial.println(which_key());
// // delay(100);
// //drow_setup();
// }
void loop() {
my_mes("HELLO");
delay(1000);
my_mes("BYE");
delay(1000);
my_mes(name,1);
delay(1000);
my_mes(age, 0, 4);
delay(1000);
my_mes1("ABC",0,'m');
delay(1000);
}
void my_mes(char*arr)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(arr);
}
void my_mes(char*arr, unsigned short row)
{
lcd.clear();
lcd.setCursor(0,row);
lcd.print(arr);
}
void my_mes(char*arr, unsigned short row, unsigned short colum)
{
lcd.clear();
lcd.setCursor(colum,row);
lcd.print(arr);
}
void my_mes1(char*arr, unsigned short row, char pos)
{
lcd.clear();
short colum = 0;
int len = sizeof(arr)/sizeof(arr[0])+1;
switch (pos)
{
case 'l':
my_mes(arr,row,colum);
break;
case 'r':
colum = LCD_LEN - len;
my_mes(arr,row,colum);
break;
case 'm':
colum = (LCD_LEN - len)/2;
my_mes(arr,row,colum);
break;
default:
break;
}
}
int which_key()
{
char key = keypad.getKey();
switch (key)
{
case '2':
return 1;
case '8':
return -1;
default:
return 0;
}
}