#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <RTClib.h>
RTC_DS1307 rtc;
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
LiquidCrystal_I2C lcd(0x27, 20, 4);
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int Buzzer = 11;
void setup()
{
Serial.begin(57600);
Wire.begin();
lcd.init();
lcd.backlight();
lcd.home();
lcd.setCursor(0,1);
lcd.print("User Number:");
lcd.setCursor(0,2);
lcd.print("T:");
lcd.setCursor(9,2);
lcd.print("V:");
lcd.setCursor(0,3);
lcd.print("%DRC:");
lcd.blink();
lcd.setCursor(19,1);
pinMode(Buzzer,OUTPUT);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
digitalWrite(Buzzer,HIGH);
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!");
}
}
void loop()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
lcd.print(key);
lcd.setCursor(19,1);
beep();
}
Time();
}
void beep()
{
digitalWrite(Buzzer,LOW);
delay(50);
digitalWrite(Buzzer, HIGH);
}
/*void Temp()
{
int analogValue = analogRead(A0);
float temp = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
lcd.setCursor(2,2);
lcd.print(temp);
lcd.print("C");
lcd.print(" ");
}
void Volt()
{
int val=analogRead(A1);
float volt;
volt =((val/1023.0)*5.0);
lcd.setCursor(11,2);
lcd.print(volt);
lcd.print("V");
lcd.print(" ");
}*/
void Time()
{
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(") ");
lcd.setCursor(19,1);
//delay(5000);
}