#include <LiquidCrystal.h>
#include <RTClib.h>
LiquidCrystal lcd (22,23,5,18,19,21);
int led=33;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup() {
pinMode(led, OUTPUT);
lcd.begin(16, 2);
Serial.begin(57600);
#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();
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));
}
// When time needs to be re-set on a previously configured device, 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));
}*/
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(led, HIGH);
delay(5000); // this speeds up the simulation
digitalWrite(led, LOW);
delay(1000);
/*lcd.setCursor(0, 0);
lcd.print(" HOLA ");
lcd.setCursor(0, 2);
lcd.print(" MUNDO CRUEL ");
delay(100);*/
DateTime now = rtc.now();
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print(" (");
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print(") ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.println();
lcd.print(" since midnight 1/1/1970 = ");
lcd.print(now.unixtime());
lcd.print("s = ");
lcd.print(now.unixtime() / 86400L);
lcd.println("d");
// calculate a date which is 7 days, 12 hours, 30 minutes, and 6 seconds into the future
DateTime future (now + TimeSpan(7,12,30,6));
lcd.print(" now + 7d + 12h + 30m + 6s: ");
lcd.print(future.year(), DEC);
lcd.print('/');
lcd.print(future.month(), DEC);
lcd.print('/');
lcd.print(future.day(), DEC);
lcd.print(' ');
lcd.print(future.hour(), DEC);
lcd.print(':');
lcd.print(future.minute(), DEC);
lcd.print(':');
lcd.print(future.second(), DEC);
lcd.println();
lcd.println();
delay(3000);
}