#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
LiquidCrystal_I2C lcd(0x27, 16, 2);
RTC_DS1307 rtc;
char key;
int keylimit = 0;
int LCDRow = 0;
const byte ROWS = 4;//keypad
const byte COLS = 4;
char keys [ROWS] [COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {13, 12, 11, 10};//keypad
byte colPins[COLS] = {9, 8, 7, 6};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void time(){
DateTime now = rtc.now();//print time
lcd.setCursor(0, 0);
lcd.print("Time: ");
if (now.hour() < 10) {
lcd.print("0"); // Add a leading zero if the hour value is less than 10
}
lcd.print(now.hour(), DEC);
lcd.print(":");
if (now.minute() < 10) {
lcd.print("0"); // Add a leading zero if the minute value is less than 10
}
lcd.print(now.minute(), DEC);
//delay(5000); // Wait for 1 second before updating the display
//return;
}
void setup(){
Serial.begin(115200);
lcd.begin(16,2);
lcd.init();//lcd
lcd.backlight();
rtc.begin(); // Initialize the RTC module
}
void loop(){
time();//call void time(26)
key =keypad.getKey();
lcd.setCursor(LCDRow, 1);
if(key){
lcd.print(key);
lcd.setCursor(++LCDRow, 1);
keylimit++;
}
if (keylimit == 4){
lcd.clear();
LCDRow = 0;
keylimit = 0;
}
}