释放双眼,带上耳机,听听看~!
#include <ESP8266WiFi.h>
#include <TimeLib.h>
#include <NtpClientLib.h>
#include <U8g2lib.h>
#include <Wire.h>
#include <SimpleTimer.h>
int8_t timeZone = 8;
const PROGMEM char *ntpServer = "ntp1.aliyun.com";
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
SimpleTimer timer;
void Simple_timer_1() {
u8g2.firstPage();
do
{
page1();
}while(u8g2.nextPage());
}
void page1() {
u8g2.setFont(u8g2_font_wqy16_t_gb2312);
u8g2.setFontPosTop();
u8g2.setCursor(0,0);
u8g2.print(String(NTP.getDateYear()) + String("年") + String(NTP.getDateMonth()) + String("月") + String(NTP.getDateDay()) + String("日"));
u8g2.setFont(u8g2_font_timB24_tf);
u8g2.setFontPosTop();
u8g2.setCursor(0,20);
u8g2.print(String(NTP.getTimeHour24()) + String(":") + String(NTP.getTimeMinute()) + String(":") + String(NTP.getTimeSecond()));
}
void setup(){
WiFi.begin("dorobz", "doro2020");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
NTP.setInterval (600);
NTP.setNTPTimeout (1500);
NTP.begin (ntpServer, timeZone, false);
u8g2.setI2CAddress(0x3C*2);
u8g2.begin();
timer.setInterval(1000L, Simple_timer_1);
u8g2.enableUTF8Print();
}
void loop(){
timer.run();
}