#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] ={
{'1','2','3','U'},
{'4','5','6','D'},
{'7','8','9','L'},
{'#','0','*','R'}
};
byte rowPins[ROWS] = {5,4,3,2};
byte colPins[COLS] = {9,8,7,6};
Keypad keypad = Keypad( makekeymap(keys), rowPins, colPins,ROWS,COLS);
RTC_DS1307 RTC;
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
Serial.begin(9600);
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(2023,1,11,16,16,16));
lcd.init();
lcd.backlight();
while(1)
{
SetTime();
}
}
void loop() {
DateTime now = RTC.now();
lcd.setCursor(3,0);
lcd.print(now.year());
lcd.print('-');
lcd.print(now.month());
lcd.print('-');
lcd.print(now.day());
lcd.setCursor(4,1);
lcdData(now.hour());
lcd.print(':');
lcdData(now.minute());
lcd.print(':');
lcdData(now.second());
}
void lcdData(uint8_t data)
{
if(data<10)
{
lcd.print(0);
lcd.print(data);
}
else
{
lcd.print(data);
}
}
void SetTime()
{
lcd.setCursor(3,0);
lcd.print("___-___-___");
lcd.setCursor(4,1);
lcd.print("__:__:__");
lcd.setCursor(3,0);
while(1)
{
CursorTwink(3,0);
}
}
void CursorTwink(uint8_t col, uint8_t row)
{
lcd.setCursor(col, row);
lcd.print(' ');
delay(100);
lcd.setCursor(col, row);
lcd.print('_');
}