Skip to content

Instantly share code, notes, and snippets.

@cyrus007
Created October 5, 2017 21:28
Show Gist options
  • Save cyrus007/a07b497fbc9ee1e3460496006faf9847 to your computer and use it in GitHub Desktop.
Save cyrus007/a07b497fbc9ee1e3460496006faf9847 to your computer and use it in GitHub Desktop.
ESP8266-12E based NTP display
#include <Arduino.h>
#include <stdint.h>
#include <TFTv2.h>
#include <SPI.h>
#include <NTPClient.h>
// change next line to use with another board/shield
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char *ssid = "<SSID>";
const char *password = "<PASSWORD>";
WiFiUDP ntpUDP;
// You can specify the time server pool and the offset (in seconds, can be
// changed later with setTimeOffset() ). Additionaly you can specify the
// update interval (in milliseconds, can be changed using setUpdateInterval() ).
NTPClient timeClient(ntpUDP, "north-america.pool.ntp.org", 3600, 60000);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
timeClient.begin();
TFT_BL_ON; //turn on the background light
Tft.TFTinit(); //init TFT library
}
char *timetext;
void loop() {
timeClient.update();
timetext = strdup(timeClient.getFormattedTime().c_str());
Serial.println(timetext);
Tft.drawString(timetext,10,10,4,CYAN); //at:(10, 10), size:4, color:CYAN
free(timetext);
delay(1000);
}
[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
; NTPClient @https://github.com/arduino-libraries/NTPClient
; TFT_Touch_Shield_V2 @https://github.com/Seeed-Studio/TFT_Touch_Shield_V2/
lib_deps =
NTPClient
ILI9341
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment