#include <stdio.h>
#include <DS1302.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
namespace {
const int kCePin = 5; // Chip Enable
const int kIoPin = 6; // Input/Output
const int kSclkPin = 7; // Serial Clock
// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);
String dayAsString(const Time::Day day) {
switch (day) {
case Time::kSunday: return "Sun,";
case Time::kMonday: return "Mon,";
case Time::kTuesday: return "Tue,";
case Time::kWednesday: return "Wed,";
case Time::kThursday: return "Thu,";
case Time::kFriday: return "Fri,";
case Time::kSaturday: return "Sat,";
}
return "Err,";
}
void printTime() {
// Get the current time and date from the chip.
Time t = rtc.time();
// Name the day of the week.
const String day = dayAsString(t.day);
// Format the time and date and insert into the temporary buffer.
char buf[50];
// Format the first line
snprintf(buf, sizeof(buf), "%s %02d-%02d-%04d",
day.c_str(),
t.date, t.mon, t.yr);
Serial.println(buf); // Print to serial for debugging
/*lcd.setCursor(0, 0);
lcd.print(buf);*/
// Move to the second line
lcd.setCursor(0, 1);
// Format the second line
snprintf(buf, sizeof(buf), "%s %02d:%02d:%02d",
day.c_str(), t.hr, t.min, t.sec);
lcd.setCursor(0, 0);
lcd.print(buf);
/*
Serial.println(buf); // Print to serial for debugging
lcd.print(buf); // Print to LCD
*/
}
} // namespace
void UI(){
lcd.setCursor(14, 0);
lcd.print("FL"); //Phase name
lcd.setCursor(0, 1);
lcd.print("FLASHING AX=000");
}
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
// Initialize a new chip by turning off write protection and clearing the
// clock halt flag. These methods needn't always be called. See the DS1302
// datasheet for details.
rtc.writeProtect(false);
rtc.halt(false);
// Make a new time object to set the date and time.
// Sunday, September 22, 2013 at 01:38:50.
Time t(2024, 7, 11, 19, 46, 20, Time::kThursday);
// Set the time and date on the chip.
//rtc.time(t);
}
// Loop and print the time every second.
void loop() {
printTime(); UI();
delay(1000);
}