#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 20, 4);
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
#define LED1 23
#define SW1 19
boolean SW1_Status;
void setup() {
// put your setup code here, to run once:
pinMode(LED1, OUTPUT);
pinMode(SW1, INPUT);
Serial.begin(115200);
lcd.init();
lcd.backlight();
lcd.setCursor(6, 0); lcd.print("Nawapon");
lcd.setCursor(0, 2); lcd.print("Date");
lcd.setCursor(13, 2); lcd.print("Time");
//lcd.setCursor(15, 3); lcd.print("15,3");
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}
unsigned int
void loop() {
SW1_Status = digitalRead(SW1);
if (SW1_Status == LOW)
{
digitalWrite(LED1, HIGH);
} else
{
digitalWrite(LED1, LOW);
}
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
lcd.setCursor(0, 3);
lcd.print(now.year()); lcd.print("/");
lcd.print(now.month()); lcd.print("/");
lcd.print(now.day()); lcd.print(" | ");
lcd.print(now.hour()); lcd.print(":");
lcd.print(now.minute()); lcd.print(":");
lcd.print(now.second()); lcd.print(" ");
}