天气时钟的制作
- 一.准备
- 代码
- 演示效果
一.准备
我的天气时钟的制作是基于太极创客制作的<ESP8266_Seniverse.h>和网上天气时钟项目进行开发。
Nodemcu开发板
中景园0.96寸OLED(七线制SPI)
GND - GND
VCC - 3.3V
D0 - D2
D1 - D1
RES - D7
DC - D5
CS - D6
面包板
杜邦线
代码
#include <ESP8266WiFi.h>
#include <ESP8266_Seniverse.h>
#include <U8g2lib.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <WiFiManager.h>U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 4, /* data=*/ 5, /* cs=*/ 12, /* dc=*/ 14, /* reset=*/ 13);/*DI ------ D1 D0 ------- D2 DC ------- D5 CS ------- D6 RES -------D7*/// weather
const String weathers[] = {"晴", "晴", "晴", "晴", "多云", "晴间多云", "晴间多云", "大部多云", "大部多云", "阴","阵雨", "雷阵雨", "雷雨冰雹", "小雨", "中雨", "大雨", "暴雨", "大暴雨", "特大暴雨","冻雨", "雨夹雪", "阵雪", "小雪", "中雪", "大雪", "暴雪", "浮尘", "扬沙", "沙尘暴","强沙暴", "雾", "霾", "风", "大风", "飓风", "热带风暴", "龙卷风", "冷", "热", "未知"};const String test[] = {"","",""};
static const unsigned char qintian[] PROGMEM =
{
//晴,天
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0xF8,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0xFF,0x00,0x00,0x00,
0x00,0x80,0xFF,0xFF,0xFF,0x03,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0x07,0x00,0x00,0x00,0xE0,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,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
0x00,0xFC,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0x00,0xF8,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0x0F,0x00,0x00,
0x00,0x80,0xFF,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0xFC,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0x3F,0x00,0x00,0x00,
0x00,0x00,0x80,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
static const unsigned char yintian[] PROGMEM =
{
//阴,天0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xFF,0xFF,0x00,0x00,0x00,0x00,
0xF0,0x01,0xF8,0xFF,0xFF,0x01,0x00,0x00,0x00,0xFC,0x0F,0xFC,0xFF,0xFF,0x03,0x00,0x00,0x00,0xFE,0x1F,0xFE,0xFF,0xFF,0x03,0x00,0x00,0x00,0xFF,0x3F,0xFE,0xFF,0xFF,
0x07,0x00,0x00,0x80,0xFF,0x7F,0xFF,0xFF,0xFF,0x07,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xE0,0xFF,
0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,
0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0xFE,0xFF,0xFF,
0xFF,0xFF,0xFF,0x3F,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0xC0,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x0F,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/* (70 X 60 )*/};
static const unsigned char duoyun[] PROGMEM =
{
//多,云
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x07,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0xF0,0xFF,0xFF,0x03,0x00,
0x00,0x00,0x00,0xF8,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0xFC,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0xFC,0xFF,0xFF,0x0F,0x00,0x00,0x00,0x00,0xFE,0xFF,0xFF,0x1F,0x00,
0x00,0x00,0x00,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x3F,0x00,
0x00,0x00,0x80,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0x00,0xC0,0xFF,0xF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0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
static const unsigned char xiaoyu[] PROGMEM =
{
//小,雨
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0x3F,0x00,0x00,
0x00,0x00,0x00,0xE0,0xFF,0x7F,0x00,0x00,0x00,0x00,0x0F,0xF0,0xFF,0xFF,0x00,0x00,0x00,0xC0,0x7F,0xF8,0xFF,0xFF,0x01,0x00,0x00,0xF0,0xFF,0xF8,0xFF,0xFF,0x03,0x00,
0x00,0xF8,0xFF,0xFD,0xFF,0xFF,0x03,0x00,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,0x07,0x00,
0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0x07,0x00,
0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,
0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,
0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,
0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
static const unsigned char zhongyu[] PROGMEM =
{
//中,雨
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x07,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0x1F,0x00,0x00,
0x00,0x00,0x00,0xC0,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0xFF,0x00,0x00,0x00,0x80,0x1F,0xF0,0xFF,0xFF,0x01,0x00,0x00,0xE0,0x3F,0xF8,0xFF,0xFF,0x01,0x00,
0x00,0xF8,0xFF,0xF8,0xFF,0xFF,0x03,0x00,0x00,0xF8,0xFF,0xFD,0xFF,0xFF,0x03,0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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x80,0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x80,0x87,0x07,0x00,0x00,0x00,
0x00,0x00,0x80,0x87,0x07,0x00,0x00,0x00,0x00,0x00,0x80,0x03,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/* (60 X 60 )*/
};
static const unsigned char dayu[] PROGMEM =
{
//大,雨
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0x03,0x00,0x00,
0x00,0x00,0x00,0xF0,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,0xF8,0xFF,0x1F,0x00,0x00,0x00,0x80,0x03,0xFC,0xFF,0x3F,0x00,0x00,0x00,0xF0,0x1F,0xFE,0xFF,0x3F,0x00,0x00,
0x00,0xFC,0x3F,0xFE,0xFF,0x7F,0x00,0x00,0x00,0xFE,0x7F,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFE,0x7F,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,
0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,
0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,
0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x04,0x00,0x00,0x00,
0x00,0x00,0x30,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x1E,0x00,0x00,0x00,
0x00,0x00,0x38,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/* (60 X 60 )*/
};
typedef struct
{int zuigaowendu;int zuidiwendu;int shidu;int tianqitubiao;
}tianqixinxi; //最高温最低温和湿度和天气现象代码的结构体
tianqixinxi day1,day2,day3;int OnTime = 0; //显示变量const char* ssid = "***"; // 连接WiFi名
const char* password = "***"; // 连接WiFi密码
String reqUserKey = "***";// 私钥
String reqLocation = "***";// 城市
String reqUnit = "c";// 摄氏/华氏WeatherNow weatherNow;
Forecast forecast;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "ntp1.aliyun.com", 60 * 60 * 8, 30 * 60 * 1000);void connectWiFi(); //函数声明
void DisplayTianqi();
void DisplayTime();
void Get_weather();void setup() {Serial.begin(115200);u8g2.begin();u8g2.enableUTF8Print();u8g2.clearBuffer();u8g2.sendBuffer();delay(850);connectWiFi();// 配置心知天气请求信息weatherNow.config(reqUserKey, reqLocation, reqUnit);forecast.config(reqUserKey, reqLocation, reqUnit);timeClient.begin();
}void loop() {u8g2.clearBuffer();// 清空显示设备内部缓冲区u8g2.setFont(u8g2_font_wqy12_t_gb2312);DisplayTianqi(); //函数调用DisplayTime();Get_weather();u8g2.sendBuffer();// 显示缓冲区内容delay(10000);
}void display_tq(int dday,int tq,int dw,int gw,int sd)
{switch(dday) //显示今明后天{case 0:u8g2.setCursor(85, 15); //设置光标位置u8g2.print("今天");break; case 1:u8g2.setCursor(85, 15);u8g2.print("明天");break;case 2:u8g2.setCursor(85, 15);u8g2.print("后天");break;} switch(tq) //显示天气图片{case 0:u8g2.drawXBMP( 0 , 0 , 60 , 60, qintian );break;case 4:u8g2.drawXBMP( 0 , 0 , 60 , 60, duoyun );break;case 9:u8g2.drawXBMP( 0 , 0 , 70 , 60, yintian );break;case 13:u8g2.drawXBMP( 0 , 0 , 60 , 60, xiaoyu );break;case 14:u8g2.drawXBMP( 0 , 0 , 60 , 60, zhongyu );break;case 15:u8g2.drawXBMP( 0 , 0 , 60 , 60, dayu );break;}u8g2.setCursor(90,30);String str3 = weathers[tq]; //显示天气(中文)u8g2.print(str3);u8g2.setCursor(70, 45);String str1 = test[0] + dw + "-" + gw + "℃"; //显示最低温度到最高温度u8g2.print(str1);u8g2.setCursor(70, 60);u8g2.print("湿度:");u8g2.setCursor(100, 60);String str2 = test[1] + sd + "%"; //显示湿度u8g2.print(str2);
} void DisplayZZXS(int dday)
{switch(dday){case 0:display_tq(dday,day1.tianqitubiao,day1.zuidiwendu,day1.zuigaowendu,day1.shidu);break; case 1:display_tq(dday,day2.tianqitubiao,day2.zuidiwendu,day2.zuigaowendu,day2.shidu);break; case 2:display_tq(dday,day3.tianqitubiao,day3.zuidiwendu,day3.zuigaowendu,day3.shidu);break; }
}void DisplayTianqi()
{if(OnTime > 1){DisplayZZXS(OnTime-2);//Serial.println("打印天气中"); }
}void Get_weather()
{if (millis()> 5000 && forecast.update()) { // 每五秒获取一次天气数据{day1.tianqitubiao = forecast.getDayCode(0);day1.zuigaowendu = forecast.getHigh(0);day1.zuidiwendu = forecast.getLow(0);day1.shidu = forecast.getHumidity(0);day2.tianqitubiao = forecast.getDayCode(1);day2.zuigaowendu = forecast.getHigh(1);day2.zuidiwendu = forecast.getLow(1);day2.shidu = forecast.getHumidity(1);day3.tianqitubiao = forecast.getDayCode(2);day3.zuigaowendu = forecast.getHigh(2);day3.zuidiwendu = forecast.getLow(2);day3.shidu = forecast.getHumidity(2);OnTime++; //显示标志位 0,1,2显示时间 3显示今天天气 4显示明天天气 5显示后天天气OnTime%=5; }}
}void DisplayTime()
{u8g2.setFont(u8g2_font_wqy16_t_gb2312);if(OnTime ==0 or OnTime == 1){u8g2.setCursor(55, 30);u8g2.print("深圳");if (timeClient.update()) {u8g2.setCursor(50, 50);String time = timeClient.getFormattedTime().substring(0, 5);u8g2.print(time);}}
}// 连接WiFi
void connectWiFi() {// 建立WiFiManager对象WiFiManager wifiManager;// 自动连接WiFi。以下语句的参数是连接ESP8266时的WiFi名称wifiManager.autoConnect("AutoConnectAP");
}
演示效果
链接: link.