#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
//WiFi Creds
const char *ssid = "Insert your router here";
const char *password = "router password";
//Clock variables
const long utcOffsetInSeconds = 0;
char daysOfTheWeek[7][12] = {"Sunday ", "Monday ", "Tuesday ", "Wednesday", "Thursday ", "Friday ", "Saturday "};
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
//i2c Screen definitions
LiquidCrystal_I2C lcd(0x3F, 20, 4);
uint8_t bell[8] = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
uint8_t note[8] = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0};
uint8_t clock[8] = {0x0, 0xe, 0x15, 0x17, 0x11, 0xe, 0x0};
uint8_t heart[8] = {0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0};
uint8_t duck[8] = {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
uint8_t check[8] = {0x0, 0x1 ,0x3, 0x16, 0x1c, 0x8, 0x0};
uint8_t cross[8] = {0x0, 0x1b, 0xe, 0x4, 0xe, 0x1b, 0x0};
uint8_t retarrow[8] = { 0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};
void setup(){
Serial.begin(115200);
Wire.begin(D2, D1);
lcd.begin();
lcd.createChar(0, bell);
lcd.createChar(1, note);
lcd.createChar(2, clock);
lcd.createChar(3, heart);
lcd.createChar(4, duck);
lcd.createChar(5, check);
lcd.createChar(6, cross);
lcd.createChar(7, retarrow);
lcd.home();
lcd.print("Isaac's Clock ");
lcd.write(0);
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
timeClient.begin();
}
void loop() {
timeClient.update();
Serial.print(daysOfTheWeek[timeClient.getDay()]);
Serial.print(", ");
Serial.print(timeClient.getHours());
Serial.print(":");
Serial.print(timeClient.getMinutes());
Serial.print(":");
Serial.println(timeClient.getSeconds());
//Serial.println(timeClient.getFormattedTime());
lcd.setCursor(0,1);
lcd.print(timeClient.getFormattedTime());
lcd.setCursor(11,1);
lcd.print(daysOfTheWeek[timeClient.getDay()]);
displaySchedule();
delay(1000);
}
void displaySchedule()
{
lcd.setCursor(0,3);
if(timeClient.getHours() == 23 && timeClient.getMinutes() >= 20 && timeClient.getMinutes() <= 30)
{
lcd.print("Test Schedule ");
}
else if(timeClient.getHours() == 19 && timeClient.getMinutes() >= 50 && timeClient.getMinutes() <= 59)
{
lcd.print("Put your Pyjamas on ");
}
else if(timeClient.getHours() == 20 && timeClient.getMinutes() >= 00 && timeClient.getMinutes() <= 30)
{
lcd.print("Isaac Time! :-) ");
}
else if(timeClient.getHours() == 20 && timeClient.getMinutes() >= 30 && timeClient.getMinutes() <= 59)
{
lcd.print("Bed time|Sleep time ");
}
else if(timeClient.getHours() == 07 && timeClient.getMinutes() >= 00 && timeClient.getMinutes() <= 29)
{
lcd.print("Morning! Breakfast ");
}
else if(timeClient.getHours() == 07 && timeClient.getMinutes() >= 30 && timeClient.getMinutes() <= 59)
{
lcd.print("Get ready for School");
}
else
{
lcd.print(" ");
}
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.