Тема: Интернет часы ESP8266 + TFT 3'2 SPI
Основная статья - http://rcl-radio.ru/?p=67569
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <UTFT.h>
#include <SPI.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600);
extern uint8_t BigFont[],SmallFont[];
UTFT myGLCD ( ILI9341_S5P, 13, 14, 15, 0, 12 );//SDI (MOSI), SCK, CS, RESET, DC == D7 D5 D8 D3 D6
const char *ssid = "Keenetic-9009";
const char *password = "32481975";
String date_time;
float sx,sy,osx,osy,mx,my,omx,omy,hx,hy,ohx,ohy;
unsigned long times;
void setup(){
Serial.begin(9600);
WiFi.mode(WIFI_STA);WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay(500);Serial.print(".");
timeClient.begin();}
myGLCD.InitLCD(0);myGLCD.fillRect(0,0,320,240);myGLCD.setFont(BigFont);myGLCD.clrScr(); // первоначальные настройки экрана
myGLCD.fillScr(0x0000);myGLCD.setColor(0xffff);myGLCD.setBackColor(0x0000);
for(int i=0;i<360;i+=30){
sx=cos((i-90)*0.0174532925);
sy=sin((i-90)*0.0174532925);
myGLCD.drawLine(sx*120+120,sy*120+120,sx*110+120,sy*110+120);}
for(int i=0;i<360;i+=6){
sx=cos((i-90)*0.0174532925);
sy=sin((i-90)*0.0174532925);
myGLCD.drawPixel(sx*115+120,sy*115+120);}
}
void loop(){
if(millis()-times>=1000){times=millis();
while(!timeClient.update()){timeClient.forceUpdate();}
int hh = timeClient.getHours();
int mm = timeClient.getMinutes();
int ss = timeClient.getSeconds();
date_time = timeClient.getFormattedDate();
int index_date = date_time.indexOf("T");
String date = date_time.substring(0, index_date);
hx=cos(((hh*30+mm*6*0.08333333)-90)*0.0174532925);
hy=sin(((hh*30+mm*6*0.08333333)-90)*0.0174532925);
mx=cos(((mm*6+ss*6*0.01666667)-90)*0.0174532925);
my=sin(((mm*6+ss*6*0.01666667)-90)*0.0174532925);
sx=cos((ss*6-90)*0.0174532925);
sy=sin((ss*6-90)*0.0174532925);
myGLCD.setColor(0x0000);// clear
myGLCD.drawLine(osx,osy,120,120);
myGLCD.drawLine(omx,omy,120,120);
myGLCD.drawLine(ohx,ohy,120,120);
myGLCD.setColor(0xffff);
myGLCD.print("12",104,0);
myGLCD.print("6",112,225);
myGLCD.print("9",0,112);
myGLCD.print("3",224,112);
ohx = hx*70+120;
ohy = hy*70+120;
omx = mx*100+120;
omy = my*100+120;
osx = sx*110+120;
osy = sy*110+120;
myGLCD.setColor(0xf000);
myGLCD.drawLine(osx,osy,120,120);
myGLCD.setColor(0xffff);
myGLCD.drawLine(omx,omy,120,120);
myGLCD.setColor(0xfff5);
myGLCD.drawLine(ohx,ohy,120,120);
myGLCD.setColor(0xf000);
myGLCD.fillCircle(120,120,4);
myGLCD.setColor(0xffff);
///////////////////////////////////////////////////////
myGLCD.print(timeClient.getFormattedTime(),60,275);
myGLCD.print(date,45,295);
}
}//loop