#include <Arduino.h>
#include <U8g2lib.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <esp_task_wdt.h>
// 自定义CLK和SDA引脚
#define OLED_CLK 22
#define OLED_SDA 21
//#define WDT_TIMEOUT 10000 //定义看门狗时间 单位毫秒
// 构造对象
U8G2_SSD1306_128X64_NONAME_F_SW_I2C OLED(U8G2_R0, OLED_CLK, OLED_SDA, U8X8_PIN_NONE);
const char *ssid="zxcvbb"; //输入自己的wifi账号
const char *password="asdf123456"; //输入自己的wifi密码
//定义 此处是聚合数据官网给的,可以自己创建账号获得key参数
String url="http://apis.juhe.cn/simpleWeather/query"; //请求网址响应
String city="东丰"; //输入想要获得的城市
String key="df39b169ab000f5874c44a5a8027f5f4";
int shui_wei_xuan_ze_an_niu; //输入IO
int cheng_xu_xuan_ze_an_niu;
int qi_ting_an_niu;
int dian_yuan_an_niu;
const int yun_xing_deng = 2; //输出IO
const int li_he_qi = 4;
const int feng_ming = 23;
const int jin_shui = 25;
const int pai_shui = 26;
const int shui_wei_ce_liang = 27;
const int zheng_zhuan = 32;
const int fan_zhuan = 33;
unsigned long miao_lei_ji;
unsigned long bao_jing_ji_shi;
unsigned long chang_yan_shi;
unsigned long zong_shi_jian;
int piao_xi_ci_shu=3;
boolean yun_xing;
boolean qi_ting_biao_zhi;
boolean pai_jin_shui_zan_ting;
int lian_wang_huo_qu;
int huo_qu_tian_qi;
int xian_shi_biao_zhi;
int kong_qi_zhi_shu;
String dang_qian_ri_qi;
String wen_du;
String jin_ri_tian_qi;
String feng_li_ji_shu;
String feng_xiang;
String cheng_xu_xian_shi;
String shui_wei_xian_shi;
int xi_biao_zhi;
int piao_xi_biao_zhi;
int tuo_shui_biao_zhi;
int jin_shui_wan_biao_zhi;
int pai_shui_wan_biao_zhi;
int cheng_xu_xuan_ze_ji_shu;
int dan_xi;
int dan_piao_xi;
int dan_tuo_shui;
int xi_piao_xi;
int xi_tuo_shui;
int piao_xi_tuo_shui;
int pin_lv;
int shui_wei_pin_lv;
int shui_wei_xuan_ze_ji_shu;
int dao_ji_shi;
int dao_ji_shi_fen;
int dao_ji_shi_miao;
hw_timer_t *timer = NULL;//定时中断
volatile double fre = 0;//频率
unsigned long xi_tong_hao_miao;
unsigned long hao_miao_0 = 0; // 毫秒时间记录
const long hao_miao_100 = 100; // 时间间隔
unsigned long fang_dou = 0; // 毫秒时间记录
const long fang_dou_yan_shi = 500; // 时间间隔
volatile unsigned long raiseTime = 0;//前一次上升沿时间
volatile unsigned long fallTime = 0;//前一次下降沿时间
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;//自旋锁
void TaskBlink1(void *pvParameters);
void TaskBlink2(void *pvParameters);
void TaskBlink3(void *pvParameters);
void tian_qi()
{
OLED.setCursor(0,10);
OLED.print("属地 东丰");
OLED.setCursor(62,10);
OLED.print(dang_qian_ri_qi);
OLED.setCursor(0,27);
OLED.print("温度");
OLED.setCursor(25,27);
OLED.print(wen_du);
OLED.setCursor(70,27);
OLED.print(feng_li_ji_shu);
OLED.setCursor(90,27);
OLED.print(feng_xiang);
OLED.setCursor(0,43);
OLED.print("空指");
OLED.setCursor(28,43);
OLED.print(kong_qi_zhi_shu);
OLED.setCursor(44,43);
OLED.print("今天");
OLED.setCursor(68,43);
OLED.print(jin_ri_tian_qi);
}
void changeISR()//外部中断操作函数一秒钟频率
{
if(digitalRead(shui_wei_ce_liang))//现在是高电平
{
fre++;
}
}
void timer_init(void) //硬件定时中断初始化
{
timer = timerBegin(0, 80, true); //0定时器变化可选0-3,80为主频80MHz分频,true为向上计数,false向下计数
timerAttachInterrupt(timer, timerIAR, true); //timer指向已初始化的定时器,timerIAR定时器函数,true边沿触发 false电平触发
timerAlarmWrite(timer,1000*1000,true); //timer指向已初始化的定时器,1000*1000为1秒,true自动重载false只触发一次
timerAlarmEnable(timer); //启动定时器,Disable关闭定时器
}
void timerIAR() //硬件定时中断函数
{
pin_lv = fre;
fre = 0;
}
void cheng_xu_fu_wei()
{
dan_xi=0;
dan_piao_xi=0;
dan_tuo_shui=0;
xi_piao_xi=0;
xi_tuo_shui=0;
piao_xi_tuo_shui=0;
}
void cheng_xu_xuan_ze_an_niu_cheng_xu()
{
if(cheng_xu_xuan_ze_an_niu<70)//程序选择
{
if(xi_tong_hao_miao - fang_dou > fang_dou_yan_shi)
{
fang_dou=xi_tong_hao_miao;
if(cheng_xu_xuan_ze_an_niu<70)
{
while(1)
{
esp_task_wdt_reset(); //硬件看门狗复位
dian_yuan_an_niu=touchRead(15);
qi_ting_an_niu=touchRead(14);
cheng_xu_xuan_ze_an_niu=touchRead(13);
xian_shi_biao_zhi=1;
Serial.print(cheng_xu_xuan_ze_ji_shu);Serial.println(":程序标,");
if(cheng_xu_xuan_ze_an_niu<70)//程序选择
{
cheng_xu_xuan_ze_ji_shu++;
if(cheng_xu_xuan_ze_ji_shu > 9)
{
cheng_xu_xuan_ze_ji_shu=1;
}
while(1)
{
esp_task_wdt_reset();
cheng_xu_xuan_ze_an_niu=touchRead(13);
if(cheng_xu_xuan_ze_an_niu>70)
{
break;
}
}
}
if(qi_ting_an_niu<70)//启动
{
if(xi_tong_hao_miao - fang_dou > fang_dou_yan_shi)
{
fang_dou=xi_tong_hao_miao;
qi_ting_biao_zhi =! qi_ting_biao_zhi;
if(qi_ting_an_niu<70)
{
while(1)
{
esp_task_wdt_reset();
qi_ting_an_niu=touchRead(14);
if(qi_ting_an_niu>70)
{
break;
}
}
}
}
break;
}
if(dian_yuan_an_niu<70)//关闭电源
{
break;
}
}
}
}
}
}
void shui_wei_xuan_ze_an_niu_cheng_xu()
{
if(shui_wei_xuan_ze_an_niu<70)//水位选择
{
if(xi_tong_hao_miao - fang_dou > fang_dou_yan_shi)
{
fang_dou=xi_tong_hao_miao;
if(shui_wei_xuan_ze_an_niu<70)
{
while(1)
{
esp_task_wdt_reset();
dian_yuan_an_niu=touchRead(15);
qi_ting_an_niu=touchRead(14);
shui_wei_xuan_ze_an_niu=touchRead(12);
xian_shi_biao_zhi=2;
Serial.print(shui_wei_xuan_ze_ji_shu);Serial.println(":水位标,");
if(shui_wei_xuan_ze_an_niu<70)//水位选择
{
shui_wei_xuan_ze_ji_shu++;
if(shui_wei_xuan_ze_ji_shu > 6)
{
shui_wei_xuan_ze_ji_shu=1;
}
while(1)
{
esp_task_wdt_reset();
shui_wei_xuan_ze_an_niu=touchRead(12);
if(shui_wei_xuan_ze_an_niu>70)
{
break;
}
}
}
if(qi_ting_an_niu<70)//启动
{
if(xi_tong_hao_miao - fang_dou > fang_dou_yan_shi)
{
fang_dou=xi_tong_hao_miao;
qi_ting_biao_zhi =! qi_ting_biao_zhi;
if(qi_ting_an_niu<70)
{
while(1)
{
esp_task_wdt_reset();
qi_ting_an_niu=touchRead(14);
if(qi_ting_an_niu>70)
{
break;
}
}
}
}
break;
}
if(dian_yuan_an_niu<70)//关闭电源
{
break;
}
}
}
}
}
}
void xi_cheng_xu_shui_wei_que_ding_cheng_xu()
{
if(cheng_xu_xuan_ze_ji_shu==1) //确定自动程序
{
cheng_xu_fu_wei();
zong_shi_jian=0;
dao_ji_shi=22610;
cheng_xu_xuan_ze_ji_shu=0;
}
if(cheng_xu_xuan_ze_ji_shu==2) //确定洗程序
{
cheng_xu_fu_wei();
dan_xi=1;
zong_shi_jian=0;
dao_ji_shi=9000;
cheng_xu_xuan_ze_ji_shu=0;
}
if(cheng_xu_xuan_ze_ji_shu==3)
{
cheng_xu_fu_wei();
dan_piao_xi=1;
zong_shi_jian=9000;
dao_ji_shi=11110;
pai_jin_shui_zan_ting=1;
cheng_xu_xuan_ze_ji_shu=0;
}
if(cheng_xu_xuan_ze_ji_shu==4)
{
cheng_xu_fu_wei();
dan_tuo_shui=1;
zong_shi_jian=20110;
dao_ji_shi=2500;
pai_jin_shui_zan_ting=1;
cheng_xu_xuan_ze_ji_shu=0;
}
if(cheng_xu_xuan_ze_ji_shu==5)
{
cheng_xu_fu_wei();
xi_piao_xi=1;
zong_shi_jian=0;
dao_ji_shi=20110;
cheng_xu_xuan_ze_ji_shu=0;
}
if(cheng_xu_xuan_ze_ji_shu==6)
{
cheng_xu_fu_wei();
xi_tuo_shui=1;
zong_shi_jian=0;
dao_ji_shi=11500;
cheng_xu_xuan_ze_ji_shu=0;
}
if(cheng_xu_xuan_ze_ji_shu==7)
{
cheng_xu_fu_wei();
pai_jin_shui_zan_ting=1;
piao_xi_tuo_shui=1;
zong_shi_jian=9000;
dao_ji_shi=13610;
cheng_xu_xuan_ze_ji_shu=0;
}
if(shui_wei_xuan_ze_ji_shu==1) //确定水位
{
shui_wei_pin_lv=3000;
shui_wei_xuan_ze_ji_shu=0;
}
if(shui_wei_xuan_ze_ji_shu==2)
{
shui_wei_pin_lv=4000;
shui_wei_xuan_ze_ji_shu=0;
}
if(shui_wei_xuan_ze_ji_shu==3)
{
shui_wei_pin_lv=5000;
shui_wei_xuan_ze_ji_shu=0;
}
if(shui_wei_xuan_ze_ji_shu==4)
{
shui_wei_pin_lv=6000;
shui_wei_xuan_ze_ji_shu=0;
}
if(shui_wei_xuan_ze_ji_shu==5)
{
shui_wei_pin_lv=7000;
shui_wei_xuan_ze_ji_shu=0;
}
if(shui_wei_xuan_ze_ji_shu==6)
{
shui_wei_pin_lv=8000;
shui_wei_xuan_ze_ji_shu=0;
}
}
void fu_wei_guan_jiao()
{
digitalWrite(li_he_qi,LOW);
digitalWrite(jin_shui,LOW);
digitalWrite(pai_shui,LOW);
digitalWrite(zheng_zhuan,LOW);
digitalWrite(fan_zhuan,LOW);
}
void fu_wei_ji_shi()
{
bao_jing_ji_shi=0;
miao_lei_ji=0;
}
void feng_ming_qi()
{
if(bao_jing_ji_shi>11)
{
bao_jing_ji_shi=0;
}
if(bao_jing_ji_shi<5)
{
digitalWrite(feng_ming,HIGH);
}
if(5<=bao_jing_ji_shi<11)
{
digitalWrite(feng_ming,LOW);
}
}
void xi_cheng_xu()
{
if(jin_shui_wan_biao_zhi==0)
{
if(miao_lei_ji>3000)
{
feng_ming_qi();
}
if(miao_lei_ji>3050)
{
yun_xing=0;
}
digitalWrite(jin_shui,HIGH);
pai_jin_shui_zan_ting=0;
}
if(jin_shui_wan_biao_zhi==1)
{
digitalWrite(jin_shui,LOW);
pai_jin_shui_zan_ting=1;
}
if(pai_jin_shui_zan_ting==1 & jin_shui_wan_biao_zhi==1 & digitalRead(jin_shui)==0 & digitalRead(pai_shui)==0)
{
if(miao_lei_ji>300)
{
miao_lei_ji=0;
}
if(miao_lei_ji<100)
{
digitalWrite(zheng_zhuan,HIGH);
}
if(100<=miao_lei_ji&miao_lei_ji<150)
{
digitalWrite(zheng_zhuan,LOW);
}
if(150<=miao_lei_ji&miao_lei_ji<250)
{
digitalWrite(fan_zhuan,HIGH);
}
if(250<=miao_lei_ji&miao_lei_ji<300)
{
digitalWrite(fan_zhuan,LOW);
}
}
}
void tuo_shui_ping_heng()
{
if(pai_shui_wan_biao_zhi==0)
{
if(miao_lei_ji>3000)
{
feng_ming_qi();
}
if(miao_lei_ji>3050)
{
yun_xing=0;
}
pai_jin_shui_zan_ting=0;
}
if(pai_shui_wan_biao_zhi==1)
{
pai_jin_shui_zan_ting=1;
}
if(pai_jin_shui_zan_ting==1 &pai_shui_wan_biao_zhi==1 & digitalRead(jin_shui)==0 & digitalRead(pai_shui)==1& digitalRead(li_he_qi)==1)
{
if(miao_lei_ji>150)
{
miao_lei_ji=0;
}
if(miao_lei_ji<50)
{
digitalWrite(zheng_zhuan,HIGH);
}
if(50<=miao_lei_ji&miao_lei_ji<150)
{
digitalWrite(zheng_zhuan,LOW);
}
}
}
void piao_xi()
{
if(chang_yan_shi<1300)
{
digitalWrite(pai_shui,HIGH);
digitalWrite(li_he_qi,HIGH);
if(98<=chang_yan_shi & chang_yan_shi<700)
{
tuo_shui_ping_heng();
}
if(700<=chang_yan_shi)
{
digitalWrite(zheng_zhuan,HIGH);
}
}
if(1300<=chang_yan_shi & chang_yan_shi<1302)
{
fu_wei_guan_jiao();
}
if(1302<=chang_yan_shi)
{
xi_cheng_xu();
if(3700<=chang_yan_shi)
{
piao_xi_ci_shu-=1;
if(0 < piao_xi_ci_shu);
{
chang_yan_shi=0;
}
}
}
}
void tuo_shui()
{
digitalWrite(pai_shui,HIGH);
digitalWrite(li_he_qi,HIGH);
if(100<=chang_yan_shi & chang_yan_shi<1300)
{
tuo_shui_ping_heng();
}
if(1300<=chang_yan_shi)
{
digitalWrite(zheng_zhuan,HIGH);
}
}
void setup()
{
Serial.begin(115200);
timer_init(); //初始化硬件定时器
//esp_task_wdt_init(WDT_TIMEOUT, true);//初始化看门狗
OLED.begin(); //初始化屏幕
OLED.enableUTF8Print();//设置字体
OLED.setFont(u8g2_font_wqy12_t_gb2312b);//设置字体方向gb2312字符数7539字节208228 ,chinese1字符数411字节9491
OLED.setFontDirection(0);
pinMode(yun_xing_deng,OUTPUT);
pinMode(feng_ming,OUTPUT);
pinMode(jin_shui,OUTPUT);
pinMode(li_he_qi,OUTPUT);
pinMode(pai_shui,OUTPUT);
pinMode(zheng_zhuan,OUTPUT);
pinMode(fan_zhuan,OUTPUT);
pinMode(shui_wei_ce_liang,INPUT_PULLUP);//设定引脚上拉_PULLUP 设定引脚下拉_PULLDOWN
attachInterrupt(digitalPinToInterrupt(shui_wei_ce_liang), changeISR, RISING);//中断指定引脚函数LOW低电平触发CHANGE电平变化RISING上升沿触发FALLING下降沿触发HIGH高电平触发
xTaskCreate(
TaskBlink1
, "TaskBlink1" // 任务名
, 2048 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL
, 0 // 任务优先级, with 3 (configMAX_PRIORITIES - 1) 是最高的,0是最低的.
, NULL
);
xTaskCreate(
TaskBlink2
, "TaskBlink2" //任务名
, 2048 // 栈大小
, NULL
, 0 // 任务优先级
, NULL
);
xTaskCreate(
TaskBlink3
, "TaskBlink3" //任务名
, 10000 // 栈大小
, NULL
, 0 // 任务优先级
, NULL
);
//delay(1000);
}
void loop(){}
void TaskBlink1(void *pvParameters) // 多线程1 主程序
{
while (1)// for死循环// 多线程,每个任务必须是死循环
{
fu_wei_ji_shi();
digitalWrite(yun_xing_deng,0);
fu_wei_guan_jiao();
cheng_xu_fu_wei();
dian_yuan_an_niu=touchRead(15);//读取触摸值
qi_ting_an_niu=touchRead(14);
cheng_xu_xuan_ze_an_niu=touchRead(13);
shui_wei_xuan_ze_an_niu=touchRead(12);
Serial.print(dian_yuan_an_niu);Serial.print(":电源--");Serial.print(qi_ting_an_niu);Serial.print(":启停--");Serial.print(cheng_xu_xuan_ze_an_niu);Serial.print(":程序--");Serial.print(shui_wei_xuan_ze_an_niu);Serial.print(":水位--");Serial.print(pin_lv);Serial.println(":频率计");
zong_shi_jian=0;
chang_yan_shi=0;
dao_ji_shi = 22610;
qi_ting_biao_zhi=0;
pai_jin_shui_zan_ting=0;
cheng_xu_xuan_ze_ji_shu=1;
shui_wei_xuan_ze_ji_shu=1;
cheng_xu_xian_shi="自动";
shui_wei_xian_shi="10升水";
unsigned long xi_tong_hao_miao = millis();
if(dian_yuan_an_niu<70)
{
if(xi_tong_hao_miao - fang_dou > fang_dou_yan_shi)
{
fang_dou=xi_tong_hao_miao;
if(dian_yuan_an_niu<70)
{
digitalWrite(yun_xing_deng,1);
while(1)
{
esp_task_wdt_reset();
dian_yuan_an_niu=touchRead(15);
if(dian_yuan_an_niu>70)
{
yun_xing =! yun_xing;
xian_shi_biao_zhi=0;
break;
}
}
}
}
}
if(yun_xing==1)
{
while(1)
{
Serial.print(digitalRead(jin_shui));Serial.print(":进水阀,");Serial.print(digitalRead(li_he_qi));Serial.print(":离合器,");
Serial.print(digitalRead(pai_shui));Serial.print(":排水阀,");Serial.print(digitalRead(feng_ming));Serial.print(":蜂鸣器,");
Serial.print(digitalRead(zheng_zhuan));Serial.print(":正转,");Serial.print(digitalRead(fan_zhuan));Serial.print(":反转,");Serial.print(pin_lv);Serial.print(":频率计,");
Serial.print(pai_shui_wan_biao_zhi);Serial.print(jin_shui_wan_biao_zhi);Serial.print(pai_jin_shui_zan_ting);Serial.print(xi_biao_zhi);Serial.print(piao_xi_biao_zhi);Serial.print(tuo_shui_biao_zhi);Serial.print(":标志,");Serial.print(cheng_xu_xuan_ze_ji_shu);Serial.print(":程序标,");
Serial.print(miao_lei_ji);Serial.print(":秒累计,");Serial.print(bao_jing_ji_shi);Serial.print(":报警时,");Serial.print(chang_yan_shi);Serial.print(":长延时,");Serial.print(dao_ji_shi);Serial.print(":倒计时");Serial.print(zong_shi_jian);Serial.print(":总时间,");
Serial.println();
unsigned long xi_tong_hao_miao = millis();
dian_yuan_an_niu=touchRead(15);
qi_ting_an_niu=touchRead(14);
cheng_xu_xuan_ze_an_niu=touchRead(13);
shui_wei_xuan_ze_an_niu=touchRead(12);
if(dian_yuan_an_niu<70)//关闭电源
{
if(xi_tong_hao_miao - fang_dou > fang_dou_yan_shi)
{
fang_dou=xi_tong_hao_miao;
if(dian_yuan_an_niu<70)
{
while(1)
{
esp_task_wdt_reset();
dian_yuan_an_niu=touchRead(15);
if(dian_yuan_an_niu>70)
{
yun_xing=0;
break;
}
}
break;
}
}
}
if(qi_ting_an_niu<70)//启动
{
if(xi_tong_hao_miao - fang_dou > fang_dou_yan_shi)
{
fang_dou=xi_tong_hao_miao;
qi_ting_biao_zhi =! qi_ting_biao_zhi;
if(qi_ting_an_niu<70)
{
while(1)
{
esp_task_wdt_reset();
qi_ting_an_niu=touchRead(14);
if(qi_ting_an_niu>70)
{
break;
}
}
}
}
}
if(pin_lv > 8000)
{
pai_shui_wan_biao_zhi=1;
}
else{pai_shui_wan_biao_zhi=0;}
if(pin_lv < shui_wei_pin_lv)
{
jin_shui_wan_biao_zhi=1;
}
else{jin_shui_wan_biao_zhi=0;}
if(qi_ting_biao_zhi==1 )
{
if(xi_tong_hao_miao - hao_miao_0 > hao_miao_100)
{
hao_miao_0=xi_tong_hao_miao;
miao_lei_ji++;
bao_jing_ji_shi++;
if(pai_jin_shui_zan_ting==1)
{
dao_ji_shi = dao_ji_shi - 1;
zong_shi_jian++;
chang_yan_shi++;
}
else{digitalWrite(fan_zhuan,LOW);digitalWrite(zheng_zhuan,LOW);}
xian_shi_biao_zhi=0;
}
if(0<=zong_shi_jian & zong_shi_jian<9000)//洗时间
{
xi_biao_zhi=1;
piao_xi_biao_zhi=0;
tuo_shui_biao_zhi=0;
}
if(9000<=zong_shi_jian & zong_shi_jian<20110)//漂洗时间
{
piao_xi_biao_zhi=1;
xi_biao_zhi=0;
tuo_shui_biao_zhi=0;
}
if(20110<=zong_shi_jian & zong_shi_jian<22611)//脱水时间
{
tuo_shui_biao_zhi=1;
xi_biao_zhi=0;
piao_xi_biao_zhi=0;
}
}
if(qi_ting_biao_zhi==0)
{
fu_wei_guan_jiao();
fu_wei_ji_shi();
xi_biao_zhi=0;
piao_xi_biao_zhi=0;
tuo_shui_biao_zhi=0;
cheng_xu_xuan_ze_an_niu_cheng_xu();
shui_wei_xuan_ze_an_niu_cheng_xu();
xi_cheng_xu_shui_wei_que_ding_cheng_xu();
}
if(9000<=zong_shi_jian & zong_shi_jian<9002)//洗完复位计时
{
fu_wei_guan_jiao();
fu_wei_ji_shi();
chang_yan_shi=0;
if(dan_xi==1)
{
yun_xing=0;
}
if(xi_tuo_shui==1)
{
zong_shi_jian=20110;
}
}
if(20110<=zong_shi_jian & zong_shi_jian<20112)//漂洗完复位计时
{
fu_wei_guan_jiao();
fu_wei_ji_shi();
chang_yan_shi=0;
if(dan_piao_xi==1|xi_piao_xi==1)
{
yun_xing=0;
}
}
if(22616<zong_shi_jian)//结束退出
{
yun_xing=0;
break;
}
if(yun_xing==0)//结束退出
{
break;
}
if(xi_biao_zhi==1)
{
xi_cheng_xu();
}
if(piao_xi_biao_zhi==1)
{
piao_xi();
}
if(tuo_shui_biao_zhi==1)
{
tuo_shui();
}
}
}
}
}
void TaskBlink2(void *pvParameters) // 多线程2 OLED显示
{
OLED.begin(); //初始化屏幕
OLED.enableUTF8Print();//设置字体
OLED.setFontDirection(0);
while (1) // A Task shall never return or exit.
{
if(yun_xing==1)
{
if(xian_shi_biao_zhi==0)
{
dao_ji_shi_fen=dao_ji_shi/10/60;
dao_ji_shi_miao=dao_ji_shi/10%60;
//OLED.setFont(u8g2_font_wqy12_t_gb2312);//设置字体大小字型
OLED.clearBuffer();
tian_qi();
OLED.setCursor(0,59);
OLED.print(cheng_xu_xian_shi);
OLED.setCursor(30,59);
OLED.print("剩余时间");
OLED.setCursor(100,59);
OLED.print(":");
OLED.setCursor(85,59);
OLED.print(dao_ji_shi_fen);
OLED.setCursor(105,59);
OLED.print(dao_ji_shi_miao);
OLED.sendBuffer();
}
if(xian_shi_biao_zhi==1)
{
if(cheng_xu_xuan_ze_ji_shu==1)
{
cheng_xu_xian_shi="自动";
}
if(cheng_xu_xuan_ze_ji_shu==2)
{
cheng_xu_xian_shi="单洗";
}
if(cheng_xu_xuan_ze_ji_shu==3)
{
cheng_xu_xian_shi="单漂";
}
if(cheng_xu_xuan_ze_ji_shu==4)
{
cheng_xu_xian_shi="单脱";
}
if(cheng_xu_xuan_ze_ji_shu==5)
{
cheng_xu_xian_shi="洗漂";
}
if(cheng_xu_xuan_ze_ji_shu==6)
{
cheng_xu_xian_shi="洗脱";
}
if(cheng_xu_xuan_ze_ji_shu==7)
{
cheng_xu_xian_shi="漂脱";
}
if(cheng_xu_xuan_ze_ji_shu==8)
{
cheng_xu_xian_shi="重新获取天气";
huo_qu_tian_qi=0;
}
if(cheng_xu_xuan_ze_ji_shu==9)
{
cheng_xu_xian_shi="重新连接WiFi";
lian_wang_huo_qu=0;
}
//OLED.setFont(u8g2_font_wqy16_t_gb2312);//设置字体大小字型
OLED.clearBuffer();
OLED.setCursor(42,27);
OLED.print("程序选择");
OLED.setCursor(30,43);
OLED.print(cheng_xu_xian_shi);
OLED.sendBuffer();
}
if(xian_shi_biao_zhi==2)
{
if(shui_wei_xuan_ze_ji_shu==1)
{
shui_wei_xian_shi="10升水";
}
if(shui_wei_xuan_ze_ji_shu==2)
{
shui_wei_xian_shi="9升水";
}
if(shui_wei_xuan_ze_ji_shu==3)
{
shui_wei_xian_shi="8升水";
}
if(shui_wei_xuan_ze_ji_shu==4)
{
shui_wei_xian_shi="7升水";
}
if(shui_wei_xuan_ze_ji_shu==5)
{
shui_wei_xian_shi="6升水";
}
if(shui_wei_xuan_ze_ji_shu==6)
{
shui_wei_xian_shi="5升水";
}
OLED.clearBuffer();
OLED.setCursor(44,27);
OLED.print("水量选择");
OLED.setCursor(50,43);
OLED.print(shui_wei_xian_shi);
OLED.sendBuffer();
}
}
else{OLED.clearDisplay();}
if(xian_shi_biao_zhi==3)
{
OLED.clearBuffer();
OLED.setCursor(10,32);
OLED.print("正在连接网络请稍等");
OLED.sendBuffer();
}
if(xian_shi_biao_zhi==4)
{
OLED.clearBuffer();
OLED.setCursor(10,32);
OLED.print("正在获取天气请稍等");
OLED.sendBuffer();
}
}
}
void TaskBlink3(void *pvParameters) // 多线程3联网获取天气数据
{
xian_shi_biao_zhi=3;
while (1) // A Task shall never return or exit.
{
if(lian_wang_huo_qu == 0)
{
esp_task_wdt_reset();
WiFi.begin(ssid,password);
while(WiFi.status()!=WL_CONNECTED){
delay(500);
Serial.print(".");
}
xian_shi_biao_zhi=0;
lian_wang_huo_qu=1;
}
if(lian_wang_huo_qu==1)
{
if(huo_qu_tian_qi==0)
{
xian_shi_biao_zhi=4;
//创建HTTPCLient 对象
HTTPClient http;
//发送GET请求
http.begin(url+"?city="+city+"&key="+key);
int httpCode=http.GET();
//获取响应状态码
Serial.printf("HTTP 状态码:%d",httpCode);
//获取响应正文
String response=http.getString();
Serial.println("响应数据");
Serial.println(response);
http.end();
//创建DynamicJsonDocument对象
DynamicJsonDocument doc(1024);
//解析JSON数据
deserializeJson(doc,response);
//从解析后的JSON文档中获取值
kong_qi_zhi_shu = doc["result"]["realtime"]["aqi"].as<int>();
dang_qian_ri_qi = doc["result"]["future"][0]["date"].as<String>();
wen_du = doc["result"]["future"][0]["temperature"].as<String>();
jin_ri_tian_qi = doc["result"]["future"][0]["weather"].as<String>();
feng_xiang = doc["result"]["realtime"]["direct"].as<String>();
feng_li_ji_shu = doc["result"]["realtime"]["power"].as<String>();
xian_shi_biao_zhi=0;
huo_qu_tian_qi=1;
}
}
}
}