ESP8266读取网络时间TM1637显示时间

ESP8266读取网络时间TM1637显示时间

// change next line to use with another board/shield
#include
//#include // for WiFi shield
//#include // for WiFi 101 shield or MKR1000
#include

const char *ssid = “Meitu M4s”;
const char *password = “19950629”;
String a;
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,“ntp1.aliyun.com”,60608,30601000);

#include “TM1637.h”
#define CLK D0//pins definitions for TM1637 and can be changed to other ports
#define DIO D1
TM1637 tm1637(CLK,DIO);
void setup()
{
tm1637.init();
tm1637.point(1);
tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
Serial.begin(115200);

WiFi.begin(ssid, password);

while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( “.” );
}
timeClient.begin();

}
void loop()
{

timeClient.update();
//Serial.println(timeClient.getFormattedTime());
a=timeClient.getFormattedTime();
//Serial.println(a);
String h1=a.substring(0,1);
String m1=a.substring(3,4);
String h2=a.substring(1,2);
String m2=a.substring(4,5);
int hour_1=h1.toInt();
int minture_1=m1.toInt();
int hour_2=h2.toInt();
int minture_2=m2.toInt();
tm1637.display(0,hour_1);
tm1637.display(1,hour_2);
tm1637.display(2,minture_1);
tm1637.display(3,minture_2);

}

你可能感兴趣的:(ESP8266读取网络时间TM1637显示时间)