1 Star 0 Fork 8

田胜蓝/ESP8266_OLED手表

forked from KBCX/ESP8266_OLED手表 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ESP8266 OLED.txt 22.56 KB
一键复制 编辑 原始数据 按行查看 历史
KBCX 提交于 2022-04-01 00:53 . 代码
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
#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();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tianword/esp8266--oled-watch.git
git@gitee.com:tianword/esp8266--oled-watch.git
tianword
esp8266--oled-watch
ESP8266_OLED手表
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385