// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include "RTClib.h"
#include <Wire.h>
#include "LiquidCrystal_I2C.h"
#include <Keypad.h>
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 20, 4);
const float BETA = 3950;
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup ()
{lcd.blink();
Serial.begin(57600);
Wire.begin();
/*#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif*/
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
if (! rtc.isrunning())
{
Serial.println("RTC is NOT running, let's set the time!");
}
lcd.init();
lcd.backlight();
lcd.setCursor(5,1);
}
void loop ()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
lcd.print(key);
lcd.setCursor(5,1);
}
DateTime now = rtc.now();
lcd.setCursor( 0,0);
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print(" (");;
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.print(") ");
//delay(3000);
}