代码拉取完成,页面将自动刷新
同步操作将从 KBCX/ESP8266_OLED手表 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266_Seniverse.h>
#include <SimpleTimer.h>
#include <U8g2lib.h>
#include <Ticker.h>
#include <EEPROM.h>
static unsigned char bitmap1[] =
{0xF8, 0x03, 0x04, 0x04, 0x02, 0x08, 0x01, 0x10, 0xF0, 0x01, 0x08, 0x02, 0x04, 0x04, 0x00, 0x00, 0xE0, 0x00, 0xE0, 0x00, 0xE0, 0x00};
static unsigned char bitmap2[] =
{0xFC, 0x07, 0x04, 0x04, 0x44, 0x04, 0xF4, 0x05, 0x44, 0x04, 0xFC, 0x07, 0x04, 0x04, 0xF4, 0x05, 0x14, 0x05, 0xF4, 0x05, 0x02, 0x04, 0x01, 0x07, /*"周",0*/};
static unsigned char bitmap3[] =
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"一",1*/};
static unsigned char bitmap4[] =
{0x00, 0x00, 0x00, 0x00, 0xFE, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, /*"二",2*/};
static unsigned char bitmap5[] =
{0x00, 0x00, 0xFE, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, /*"三",3*/};
static unsigned char bitmap6[] =
{0x00, 0x00, 0xFE, 0x07, 0x92, 0x04, 0x92, 0x04, 0x92, 0x04, 0x92, 0x04, 0x92, 0x04, 0x0A, 0x07, 0x06, 0x04, 0x02, 0x04, 0xFE, 0x07, 0x02, 0x04, /*"四",4*/};
static unsigned char bitmap7[] =
{0x00, 0x00, 0xFF, 0x03, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0xFE, 0x01, 0x08, 0x01, 0x08, 0x01, 0x08, 0x01, 0x04, 0x01, 0x04, 0x01, 0xFF, 0x07, /*"五",5*/};
static unsigned char bitmap8[] =
{0x10, 0x00, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x88, 0x00, 0x08, 0x01, 0x04, 0x02, 0x04, 0x02, 0x02, 0x04, 0x01, 0x04, /*"六",6*/};
static unsigned char bitmap9[] =
{0x00, 0x00, 0xFE, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0xFE, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0xFE, 0x03, 0x02, 0x02, /*"日",7*/};
static unsigned char bitmap[] =
{0x00, 0x00, 0xE6, 0x01, 0x16, 0x02, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x02, 0xE0, 0x01, 0x00, 0x00, 0x00, 0x00, /*"未命名文件",0*/};
static unsigned char yjx[] =
{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x40, 0x00, 0xE4, 0x04, 0x44, 0x04, /*雨夹雪*/};
static unsigned char yt[] =
{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*阴*/};
static unsigned char dy[] =
{0x00, 0x0A, 0x00, 0x10, 0xE0, 0x07, 0x10, 0x15, 0x10, 0x07, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*多云*/};
static unsigned char bx[] =
{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x44, 0x04, 0xEE, 0x0E, 0x44, 0x04, /*暴雪*/};
static unsigned char by[] =
{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x00, 0x00, 0x54, 0x05, 0x54, 0x05, /*暴雨*/};
static unsigned char bb[] =
{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x00, 0x00, 0x4C, 0x06, 0x48, 0x04, /*冰雹*/};
static unsigned char qt[] =
{0x40, 0x00, 0x42, 0x08, 0x04, 0x04, 0xF0, 0x01, 0x08, 0x02, 0x08, 0x02, 0x0B, 0x1A, 0x08, 0x02, 0x08, 0x02, 0xF0, 0x01, 0x04, 0x04, 0x42, 0x08, 0x40, 0x00, /*晴*/};
static unsigned char dyu[] =
{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x00, 0x00, 0x14, 0x05, 0x14, 0x05, /*大雨*/};
static unsigned char zy[] =
{0x00, 0x14, 0x00, 0x00, 0xE0, 0x17, 0x10, 0x05, 0x10, 0x07, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x00, 0x00, 0x08, 0x02, 0x08, 0x02, /*阵雨*/};
static unsigned char scb[] =
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0xD8, 0x09, 0x03, 0x12, 0x00, 0x12, 0xFE, 0x0D, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x08, 0x00, 0x04, 0x00, 0x00, /*沙尘暴*/};
static unsigned char wu[] =
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x01, 0x00, 0x00, 0xFE, 0x0F, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0x00, 0xFE, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*雾*/};
static unsigned char wm[] =
{0x00, 0x00, 0x49, 0x12, 0x00, 0x00, 0x1E, 0x0F, 0xA1, 0x10, 0xE1, 0x10, 0xE1, 0x10, 0xE1, 0x10, 0xA1, 0x10, 0x1E, 0x0F, 0x00, 0x00, 0x49, 0x12, 0x00, 0x00, /*雾霾*/};
static unsigned char xx[] =
{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x40, 0x00, 0xE0, 0x00, 0x40, 0x00, /*小雪*/};
static unsigned char xy[] =
{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x00, 0x00, 0x08, 0x02, 0x08, 0x02, /*小雨*/};
static unsigned char lzy[] =
{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x11, 0x10, 0x8A, 0x0F, 0x3C, 0x00, 0x10, 0x02, 0x08, 0x02, /*雷阵雨*/};
static unsigned char zx[] =
{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x08, 0x02, 0x1C, 0x07, 0x08, 0x02, /*中雪*/};
static unsigned char zyu[] =
{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x0E, 0x0E, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0xFE, 0x0F, 0x00, 0x00, 0x44, 0x04, 0x44, 0x04, /*中雨*/};
#define EEPROM_write(address, p) \
{ \
unsigned int i = 0; \
byte *pp = (byte *)&(p); \
for (i = 0; i < sizeof(p); i++) \
EEPROM.write(address + i, pp[i]); \
EEPROM.end(); \
}
#define EEPROM_read(address, p) \
{ \
unsigned int i = 0; \
byte *pp = (byte *)&(p); \
for (i = 0; i < sizeof(p); i++) \
pp[i] = EEPROM.read(address + i); \
}
const char *ssid = "V20"; // WIFI名称
const char *password = "123456789"; // WIFI密码
int pingnian[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int runnian[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
U8G2_SH1106_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, SCL, SDA, U8X8_PIN_NONE);
HTTPClient http;
String GetUrl;
String response;
Ticker myTicker;
WeatherNow weatherNow;
Forecast forecast;
SimpleTimer timer;
volatile unsigned long triggertime = 0; //按键按下,第一次触发中断的时刻
volatile unsigned long delta = 200; //去抖期的时长 (毫秒)
String S, F, M, X, N, Y, R, TQ, FX;
int s = 0, f = 0, m = 0, x = 0, n = 0, y = 0, r = 0; //时 分 秒 星期 年 月 日
int js = 0, jf = 0, jm = 0; // 计时 计分 计秒
int ns = 0, nf = 0; // 闹钟 时 分
int i = 0, j = 0, t = 0, jk = 0; //按键控制
bool k = 0, h = 1; //布尔类型
int dc = 0; //电池
double val, val1; //电量
int ji = 0, WD = 0, ZGWD = 0, ZDWD = 0, SD = 0, FL = 0;
int jfm = 0, ys;
struct config_type
{
int date1;
int date3;
float date2;
} cfgtype;
//获取天气
void Simple_timer_1()
{
if (weatherNow.update() && forecast.update())
{
WD = weatherNow.getDegree();
TQ = weatherNow.getWeatherText();
ZGWD = forecast.getHigh(0);
ZDWD = forecast.getLow(0);
FX = forecast.getWindDirection(0); // 获取风向信息
FL = forecast.getWindScale(0); // 获取风力信息
SD = forecast.getHumidity(0); // 获取湿度信息
}
}
// 14管脚中断执行任务
IRAM_ATTR void attachInterrupt_fun_14()
{
if (millis() - triggertime > delta) //如果中断内时间减去上次进入中断时间大于消抖时间
{
triggertime = millis();
i++;
if (i > 2)
{
i = 0;
}
}
}
// 12管脚中断执行任务
IRAM_ATTR void attachInterrupt_fun_12()
{
if (millis() - triggertime > delta) //如果中断内时间减去上次进入中断时间大于消抖时间
{
triggertime = millis();
EEPROM.begin(128); //申请内存空间
if (i == 0)
{
cfgtype.date3 = ys;
cfgtype.date1 = ns;
cfgtype.date2 = nf;
EEPROM_write(0, cfgtype); //写入到0地址的结构体变量
}
if (i == 1)
j++;
if (j > 3)
{
j = 0;
}
if (j == 3)
{
jm = 0, jf = 0, js = 0, j = 0;
}
if (i == 2)
{
t++;
cfgtype.date3 = ys;
cfgtype.date1 = ns;
cfgtype.date2 = nf;
EEPROM_write(0, cfgtype); //写入到0地址的结构体变量
}
}
}
// 13管脚中断执行任务
IRAM_ATTR void attachInterrupt_fun_13()
{
if (millis() - triggertime > delta) //如果中断内时间减去上次进入中断时间大于消抖时间
{
triggertime = millis();
if (i == 0 && ys < 1)
ys++;
else
ys = 0;
if (i == 2)
jk = 1;
}
}
//闹钟设置
void naoz()
{
if (i == 2)
{
if (t > 1)
{
t = 0;
}
switch (t)
{
case 0:
if (jk == 1)
ns++;
break;
case 1:
if (jk == 1)
nf++;
break;
}
}
if (ns == 24)
{
ns = 0;
}
if (nf == 60)
{
nf = 0;
}
jk = 0;
}
//闹钟void
void naozhong()
{
if (s == ns && f == nf && m < 10)
{
if (h == 1)
{
tone(15, 2000);
h = 0;
}
else
{
tone(15, 0);
h = 1;
}
}
if (m > 10)
tone(15, 0);
}
//计时
void miaobiao()
{
if (jm == 100)
{
jm = 0;
jf++;
}
if (jf == 60)
{
js++;
jf = 0;
}
if (js == 24)
{
js = 0;
}
}
//时间计算
void jisuan()
{
if (m == 60)
{
m = 0;
f++;
}
if (f == 60)
{
f = 0;
s++;
}
if (s == 23 && f == 59 && m == 59)
{
s = 0;
f = 0;
m = 0;
x++;
if (x == 7)
x = 0;
if ((n % 4 == 0 && n % 100 != 0) || n % 400 == 0)
{
if (r != runnian[y - 1])
{
r++;
}
else
{
r = 1;
if (y != 12)
{
y++;
}
else
{
y = 1;
n++;
}
}
}
else
{
if (r != pingnian[y - 1])
{
r++;
}
else
{
r = 1;
if (y != 12)
{
y++;
}
else
{
y = 1;
n++;
}
}
}
}
}
// WIFI
void WIFI()
{
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
u8g2.firstPage();
do
{
u8g2.setFont(u8g2_font_wqy14_t_gb2312b);
u8g2.setFontPosTop();
u8g2.setCursor(0, 1);
u8g2.print("等待WIFI连接...");
} while (u8g2.nextPage());
delay(100);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
//网页
void wangyan()
{
GetUrl = "http://api.k780.com:88/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json&HTTP/1.1";
http.setTimeout(5000);
WiFiClient client;
http.begin(client, GetUrl);
// 从网站获得网页内容
int httpCode = http.GET();
if (httpCode > 0)
{
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK)
{
response = http.getString(); //读取响应内容
}
}
else
{
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
u8g2.firstPage();
do
{
u8g2.setFont(u8g2_font_wqy14_t_gb2312b);
u8g2.setFontPosTop();
u8g2.setCursor(0, 0);
u8g2.print(ssid);
u8g2.setCursor(0, 14);
u8g2.print(WiFi.localIP());
u8g2.setCursor(0, 30);
u8g2.print("连接成功");
} while (u8g2.nextPage());
delay(1500);
}
void tbxs(int x, int y)
{
if (TQ == "雨夹雪")
u8g2.drawXBM(x, y, 13, 13, yjx); //日
else if (TQ == "阴")
u8g2.drawXBM(x, y, 13, 13, yt); //日
else if (TQ == "多云")
u8g2.drawXBM(x, y, 13, 13, dy); //日
else if (TQ == "晴")
u8g2.drawXBM(x, y, 13, 13, qt); //日
else if (TQ == "暴雪")
u8g2.drawXBM(x, y, 13, 13, bx); //日
else if (TQ == "暴雨")
u8g2.drawXBM(x, y, 13, 13, by); //日
else if (TQ == "冰雹")
u8g2.drawXBM(x, y, 13, 13, bb); //日
else if (TQ == "大雨")
u8g2.drawXBM(x, y, 13, 13, dyu); //日
else if (TQ == "阵雨")
u8g2.drawXBM(x, y, 13, 13, zy); //日
else if (TQ == "沙尘暴")
u8g2.drawXBM(x, y, 13, 13, scb); //日
else if (TQ == "雾")
u8g2.drawXBM(x, y, 13, 13, wu); //日
else if (TQ == "雾霾")
u8g2.drawXBM(x, y, 13, 13, wm); //日
else if (TQ == "小雪")
u8g2.drawXBM(x, y, 13, 13, xx); //日
else if (TQ == "小雨")
u8g2.drawXBM(x, y, 13, 13, xy); //日
else if (TQ == "雷阵雨")
u8g2.drawXBM(x, y, 13, 13, lzy); //日
else if (TQ == "中雪")
u8g2.drawXBM(x, y, 13, 13, zx); //日
else if (TQ == "中雨")
u8g2.drawXBM(x, y, 13, 13, zyu); //日
}
void xingqi(int i, int j)
{
switch (x)
{
case 0:
u8g2.drawXBM(i, j, 12, 12, bitmap9); //日
break;
case 1:
u8g2.drawXBM(i, j, 12, 12, bitmap3); //一
break;
case 2:
u8g2.drawXBM(i, j, 12, 12, bitmap4); //二
break;
case 3:
u8g2.drawXBM(i, j, 12, 12, bitmap5); //三
break;
case 4:
u8g2.drawXBM(i, j, 12, 12, bitmap6); //四
break;
case 5:
u8g2.drawXBM(i, j, 12, 12, bitmap7); //五
break;
case 6:
u8g2.drawXBM(i, j, 12, 12, bitmap8); //六
break;
}
}
//主页
void zhuye()
{
if (i == 0) //主页
{
//电图标
if (!digitalRead(16))
{
u8g2.drawFrame(125, 3, 2, 7);
u8g2.drawFrame(107, 1, 18, 11);
u8g2.drawBox(109, 3, val, 7);
}
else
{
u8g2.drawFrame(107, 1, 18, 11);
u8g2.drawFrame(125, 3, 2, 7);
u8g2.drawTriangle(109, 3, 116, 10, 116, 6);
u8g2.drawTriangle(116, 3, 122, 10, 116, 7);
}
// WIFI图标
if (WiFi.status() != WL_CONNECTED)
{
u8g2.setCursor(0, 0);
u8g2.print(" ");
}
else
{
u8g2.drawXBM(0, 0, 13, 11, bitmap1);
}
//秒表图标
u8g2.setFont(u8g2_font_unifont_t_symbols);
if (j == 1 && i == 0)
{
if (k == 0)
{
u8g2.drawGlyph(15, 0, 0x23f1);
k = 1;
}
else
{
u8g2.drawGlyph(15, 0, 0x0020);
k = 0;
}
}
else
{
u8g2.drawGlyph(15, 0, 0x23f1);
}
//日期显示
tbxs(70, 0);
u8g2.setFont(u8g2_font_freedoomr10_mu);
u8g2.setCursor(40, 0);
u8g2.print(WD);
u8g2.drawXBM(55, 1, 12, 12, bitmap); //温度图标
u8g2.setCursor(0, 52);
u8g2.print(n);
u8g2.setCursor(32, 52);
u8g2.print("-");
if (y < 10)
{
u8g2.setCursor(40, 52);
u8g2.print("0" + String(y, DEC));
}
else
{
u8g2.setCursor(40, 52);
u8g2.print(y);
}
u8g2.setCursor(56, 52);
u8g2.print("-");
if (r < 10)
{
u8g2.setCursor(65, 52);
u8g2.print("0" + String(r, DEC));
}
else
{
u8g2.setCursor(65, 52);
u8g2.print(r);
}
//时间显示
u8g2.setFont(u8g2_font_freedoomr10_mu);
u8g2.setCursor(39, 25);
u8g2.print(":");
u8g2.setCursor(85, 25);
u8g2.print(":");
u8g2.setFont(u8g2_font_freedoomr25_mn);
if (s < 10) //如果<10整形转字符串补0输出否则正常输出
{
u8g2.setCursor(0, 20);
u8g2.print("0" + String(s, DEC));
}
else
{
u8g2.setCursor(0, 20);
u8g2.print(s);
}
if (f < 10)
{
u8g2.setCursor(46, 20);
u8g2.print("0" + String(f, DEC));
}
else
{
u8g2.setCursor(46, 20);
u8g2.print(f);
}
if (m < 10)
{
u8g2.setCursor(91, 20);
u8g2.print("0" + String(m, DEC));
}
else
{
u8g2.setCursor(91, 20);
u8g2.print(m);
}
//匹配星期
u8g2.drawXBM(102, 52, 12, 12, bitmap2);
xingqi(115, 52);
}
}
//第一页
void diyiye()
{
//秒表显示页面
if (i == 1)
{
u8g2.setFont(u8g2_font_freedoomr10_mu);
u8g2.setCursor(39, 20);
u8g2.print(":");
u8g2.setCursor(85, 20);
u8g2.print(":");
u8g2.setFont(u8g2_font_freedoomr25_mn);
if (js < 10)
{
u8g2.setCursor(0, 15);
u8g2.print("0" + String(js, DEC));
}
else
{
u8g2.setCursor(0, 15);
u8g2.print(js);
}
if (jf < 10)
{
u8g2.setCursor(46, 15);
u8g2.print("0" + String(jf, DEC));
}
else
{
u8g2.setCursor(46, 15);
u8g2.print(jf);
}
if (jm < 10)
{
u8g2.setCursor(92, 15);
u8g2.print("0" + String(jm, DEC));
}
else
{
u8g2.setCursor(92, 15);
u8g2.print(jm);
}
}
}
//第二页
void dierye()
{
//闹钟设置时间显示页面
if (i == 2)
{
u8g2.setFont(u8g2_font_freedoomr10_mu);
switch (t)
{
case 0:
u8g2.setCursor(35, 0);
u8g2.print("*");
break;
case 1:
u8g2.setCursor(85, 0);
u8g2.print("*");
break;
}
u8g2.setFont(u8g2_font_freedoomr10_mu);
u8g2.setCursor(60, 20);
u8g2.print(":");
u8g2.setFont(u8g2_font_freedoomr25_mn);
if (ns < 10)
{
u8g2.setCursor(20, 15);
u8g2.print("0" + String(ns, DEC));
}
else
{
u8g2.setCursor(20, 15);
u8g2.print(ns);
}
if (nf < 10)
{
u8g2.setCursor(70, 15);
u8g2.print("0" + String(nf, DEC));
}
else
{
u8g2.setCursor(70, 15);
u8g2.print(nf);
}
}
}
//第二页面
void yangshi()
{
if (i == 0)
{
//当前温度显示
u8g2.setFont(u8g2_font_freedoomr10_mu);
tbxs(110, 15);
u8g2.setCursor(110, 0);
u8g2.print(WD);
u8g2.drawXBM(117, 43, 12, 12, bitmap); //温度图标
//星期显示
u8g2.drawXBM(0, 35, 12, 12, bitmap2);
xingqi(17, 35);
//线宽
u8g2.drawLine(0, 30, 128, 30);
u8g2.drawLine(102, 30, 102, 0);
u8g2.drawLine(42, 30, 42, 64);
u8g2.drawLine(95, 30, 95, 64);
//最高最低温度显示
u8g2.setCursor(98, 34);
u8g2.print(ZGWD);
u8g2.setCursor(98, 52);
u8g2.print(ZDWD);
u8g2.drawTriangle(119, 34, 123, 39, 115, 39);
u8g2.drawTriangle(119, 62, 123, 58, 116, 58);
//时间显示
u8g2.setCursor(39, 5);
u8g2.print(":");
if (m < 10)
{
u8g2.setCursor(86, 14);
u8g2.print("0" + String(m, DEC));
}
else
{
u8g2.setCursor(86, 14);
u8g2.print(m);
}
u8g2.setFont(u8g2_font_freedoomr25_mn);
if (s < 10)
{
u8g2.setCursor(0, 0);
u8g2.print("0" + String(s, DEC));
}
else
{
u8g2.setCursor(0, 0);
u8g2.print(s);
}
if (f < 10)
{
u8g2.setCursor(46, 0);
u8g2.print("0" + String(f, DEC));
}
else
{
u8g2.setCursor(46, 0);
u8g2.print(f);
}
//日期显示
u8g2.setFont(u8g2_font_freedoomr10_mu);
u8g2.setCursor(16, 52);
u8g2.print("/");
if (y < 10)
{
u8g2.setCursor(0, 52);
u8g2.print("0" + String(y, DEC));
}
else
{
u8g2.setCursor(0, 52);
u8g2.print(y);
}
if (r < 10)
{
u8g2.setCursor(24, 52);
u8g2.print("0" + String(r, DEC));
}
else
{
u8g2.setCursor(24, 52);
u8g2.print(r);
}
//风力 湿度 风向显示
u8g2.setFont(u8g2_font_wqy12_t_chinese2);
u8g2.setCursor(46, 55);
u8g2.print("FL:");
u8g2.setCursor(45, 44);
u8g2.print("SD:");
u8g2.setCursor(45, 32);
u8g2.print("FX:");
u8g2.setCursor(70, 55);
u8g2.print(FL);
u8g2.setCursor(70, 44);
u8g2.print(SD);
u8g2.setCursor(70, 32);
u8g2.print(FX);
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setCursor(87, 44);
u8g2.print("%");
}
}
//显示
void xianshi()
{
u8g2.firstPage();
do
{
u8g2.setFontPosTop();
if (ys == 0)
zhuye(); //主页
else if (ys == 1)
yangshi(); //第二主页
diyiye(); //第一页
dierye(); //第二页
} while (u8g2.nextPage());
}
//到时间时需要执行的任务
void tickerHandle()
{
jfm++;
if (jfm == 100)
{
jfm = 0;
m++;
}
if (j == 1)
jm++;
miaobiao();
jisuan();
val1 = (val1 * (5 - 1) + analogRead(A0)) / 5; // ADC滤波
val = map(val1, 40, 48, 0, 14);
}
void setup()
{
myTicker.attach(0.01, tickerHandle); //定时器0.01ms
timer.setInterval(10000L, Simple_timer_1); //定时器10s
attachInterrupt(digitalPinToInterrupt(14), attachInterrupt_fun_14, FALLING); //按键中断
attachInterrupt(digitalPinToInterrupt(13), attachInterrupt_fun_13, FALLING); //按键中断
attachInterrupt(digitalPinToInterrupt(12), attachInterrupt_fun_12, FALLING); //按键中断
weatherNow.config("请输入你的心知天气密钥", "ip", "c", "zh-Hans");
forecast.config("请输入你的心知天气密钥", "ip", "c", "zh-Hans");
u8g2.begin();
u8g2.enableUTF8Print();
Serial.begin(9600);
pinMode(16, INPUT);
pinMode(14, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(15, OUTPUT);
// 连接WiFi
WIFI();
// 读取授时网页
wangyan();
//读取到的字符串时间转int
S = response.substring(75, 77); //时
F = response.substring(78, 80); //分
M = response.substring(81, 83); //秒
X = response.substring(144, 145); //星期
N = response.substring(64, 68); //年
Y = response.substring(69, 71); //月
R = response.substring(72, 74); //日
s = S.toInt();
f = F.toInt();
m = M.toInt();
x = X.toInt();
n = N.toInt();
y = Y.toInt();
r = R.toInt();
config_type readback; //结构体变量(读)
EEPROM.begin(128); //申请内存空间
EEPROM_read(0, readback); //地址0开始读取
ns = readback.date1; // EEPROM ns读取
nf = readback.date2; // EEPROM nf读取
ys = readback.date3; // EEPROM ys读取
}
void loop()
{
timer.run();
xianshi();
naozhong();
naoz();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。