#include <Servo.h>
#include <Keypad.h>
//#include <LiquidCrystal.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); //0x27 is the i2c address, while 16 = columns, and 2 = rows.
#include<stdio.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', '*'},
{'.', '0', '=', '/'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A3, A2, A1, A0}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#include "RTClib.h"
RTC_DS1307 Rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup ()
{
lcd.init();
lcd.backlight();
lcd.clear();
Rtc.begin();
}
void loop ()
{
DateTime now = Rtc.now();
lcd.setCursor(0, 0);
lcd.print("Date: ");
lcd.print(now.day());
lcd.print("/");
lcd.print(now.month());
lcd.print("/");
lcd.print(now.year());
lcd.setCursor(0, 1);
lcd.print("Time: ");
lcd.print(now.hour());
lcd.print(":");
lcd.print(now.minute());
lcd.print(":");
lcd.print(now.second());
//Set the Date and Time Manually when '*' key is pressed
char c = keypad.getKey();
if (c == '*') {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Year: ");
int year = getData();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Month: ");
int month = getData();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter DayOfWeek: ");
int day = getData();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Hours: ");
int hour = getData();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Minutes: ");
int minute = getData();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Seconds: ");
int second = getData();
//DateTime newTime = (year, month, day, hour, minute, second);
Rtc.adjust(DateTime(year, month, day, hour, minute, second));
}
//delay(500);
}
int getData() {
String container = "";
lcd.setCursor(0, 1);
while (true) {
char c = keypad.getKey();
if (c == '/') {
break;
} else if (isDigit(c)) {
container += c;
lcd.print(c);
} else {
//Nothing
}
}
return container.toInt();
}