Difference between revisions of "WeMOS: LCD NTP Jam Digital"

From OnnoWiki
Jump to navigation Jump to search
(Created page with "#include <NTPClient.h> #include <ESP8266WiFi.h> #include <WiFiUdp.h> const char *ssid = "ssid"; const char *password = "password"; const long utcOffsetInSeconds = 3600;...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
#include <NTPClient.h>
+
#include <NTPClient.h>
#include <ESP8266WiFi.h>
+
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
+
#include <WiFiUdp.h>
 
+
#include <LiquidCrystal.h>
const char *ssid    = "ssid";
+
const char *password = "password";
+
// initialize the library with the numbers of the interface pins
 
+
// LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const long utcOffsetInSeconds = 3600;  
+
// LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
+
LiquidCrystal lcd(D6, D7, D2, D3, D4, D5);
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
+
 
 
+
const char *ssid    = "ssid";
// Define NTP Client to get time
+
const char *password = "password";
WiFiUDP ntpUDP;
+
const long utcOffsetInSeconds = 3600;  
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
+
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
 
+
void setup(){
+
// Define NTP Client to get time
  Serial.begin(115200);  
+
WiFiUDP ntpUDP;
 
+
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
  WiFi.begin(ssid, password);  
+
 
+
void setup(){
  while ( WiFi.status() != WL_CONNECTED ) {
+
  Serial.begin(115200);  
    delay ( 500 );
+
    Serial.print ( "." );
+
  WiFi.begin(ssid, password);  
  }
+
 
+
  while ( WiFi.status() != WL_CONNECTED ) {
  timeClient.begin();
+
    delay ( 500 );
}
+
    Serial.print ( "." );
 
+
  }
void loop() {
+
  timeClient.update();  
+
  timeClient.begin();
 
+
  // set up the LCD's number of columns and rows:
  Serial.print(daysOfTheWeek[timeClient.getDay()]);
+
  lcd.begin(16, 2);
  Serial.print(", ");
+
}
  Serial.print(timeClient.getHours()+6);
+
  Serial.print(":");
+
void loop() {
  Serial.print(timeClient.getMinutes());
+
  timeClient.update();  
  Serial.print(":");
+
  Serial.println(timeClient.getSeconds());
+
  // set the cursor to column 0, line 1
  //Serial.println(timeClient.getFormattedTime());
+
  // (note: line 1 is the second row, since counting begins with 0):
 
+
  lcd.setCursor(0, 0);
  delay(1000);
+
  lcd.print("              ");
}
+
  lcd.setCursor(0, 0);
 +
  lcd.print(daysOfTheWeek[timeClient.getDay()]);
 +
  // print time
 +
  lcd.setCursor(0, 1);
 +
  lcd.print("               ");
 +
  lcd.setCursor(0, 1);
 +
  lcd.print(timeClient.getHours()+6);
 +
  lcd.print(":");
 +
  lcd.print(timeClient.getMinutes());
 +
  lcd.print(":");
 +
  lcd.print(timeClient.getSeconds());
 +
  // lcd.print(timeClient.getFormattedTime());  
 +
 +
  delay(1000);
 +
}

Latest revision as of 13:33, 23 November 2019

#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
// LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
LiquidCrystal lcd(D6, D7, D2, D3, D4, D5);
 
const char *ssid     = "ssid";
const char *password = "password";
const long utcOffsetInSeconds = 3600; 
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);

void setup(){
  Serial.begin(115200); 

  WiFi.begin(ssid, password); 

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  timeClient.begin();
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
}

void loop() {
  timeClient.update(); 

  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 0);
  lcd.print("               ");
  lcd.setCursor(0, 0);
  lcd.print(daysOfTheWeek[timeClient.getDay()]);
  // print time
  lcd.setCursor(0, 1);
  lcd.print("               ");
  lcd.setCursor(0, 1);
  lcd.print(timeClient.getHours()+6);
  lcd.print(":");
  lcd.print(timeClient.getMinutes());
  lcd.print(":");
  lcd.print(timeClient.getSeconds());
  // lcd.print(timeClient.getFormattedTime()); 

  delay(1000);
}