parent
e3928a0659
commit
8e66b24dd6
1 changed files with 129 additions and 0 deletions
@ -0,0 +1,129 @@ |
||||
/* *****************************************************************
|
||||
* |
||||
this is the code for the control part of automatic home solar-powered water heated system. |
||||
*
|
||||
* *****************************************************************/ |
||||
|
||||
//announce connection moudle
|
||||
#define BLINKER_PRINT Serial |
||||
#define BLINKER_WIFI |
||||
|
||||
//declear the slider on phone
|
||||
#define Slider_1 "slider" |
||||
|
||||
//include function set
|
||||
#include <Blinker.h> |
||||
|
||||
//declear overall variable::user, password, identify key
|
||||
char auth[] = "c625b08a9549"; |
||||
char ssid[] = "TOTOLINK_3be124"; |
||||
char pswd[] = "13371035727"; |
||||
|
||||
//declear Button with certain keyname
|
||||
BlinkerButton Button1("btn-abc"); |
||||
BlinkerButton Button2("btn-on"); |
||||
BlinkerButton Button3("btn-off"); |
||||
BlinkerButton Button4("btn-start"); |
||||
//declaer Slider with certain keyname
|
||||
BlinkerSlider Slider1(Slider_1); |
||||
|
||||
//define vairable
|
||||
int counter,timer,time1,time2,a,b = 0; |
||||
float i=0; |
||||
|
||||
//Button1 function::state check
|
||||
void button1_callback(const String & state)
|
||||
{ |
||||
BLINKER_LOG2("get button1 state: ", state); |
||||
if(digitalRead(D5)){ Button1.print("未加水");}else{ Button1.print("正在加水..");}
|
||||
if(a==1){ Blinker.print("剩余分钟:"); |
||||
Blinker.print((time2-Blinker.time())/60);} |
||||
} |
||||
|
||||
//Button2 function::on
|
||||
void button2_callback(const String & state)
|
||||
{ |
||||
BLINKER_LOG2("get button2 state: ", state);
|
||||
digitalWrite(D5, LOW); |
||||
if(digitalRead(D5)){ Button2.print("停止加水");}else{ Button2.print("开始加水..");} |
||||
} |
||||
|
||||
//Button3 function::off
|
||||
void button3_callback(const String & state)
|
||||
{ |
||||
BLINKER_LOG2("get button3 state: ", state); |
||||
|
||||
digitalWrite(D5, HIGH); |
||||
|
||||
if(digitalRead(D5)){ Button3.print("加水已停止.");}else{ Button3.print("正在加水..");} |
||||
if(a==1){delay(500);Button3.print("加水已终止!");} |
||||
|
||||
a=0; //reset key var a
|
||||
} |
||||
|
||||
//Button4 function::start on
|
||||
void button4_callback(const String & state)
|
||||
{ |
||||
BLINKER_LOG2("get button4 state: ", state); |
||||
|
||||
a=1; |
||||
digitalWrite(D5, LOW); |
||||
|
||||
time1=Blinker.time(); |
||||
time2=time1+timer*60; |
||||
BLINKER_LOG2("get slider value: ", time2-Blinker.time()); |
||||
Button4.print("开始计时加水!"); |
||||
} |
||||
|
||||
//skider function
|
||||
void slider1_callback(int32_t value) |
||||
{ |
||||
timer=value; |
||||
} |
||||
|
||||
//setup function
|
||||
void setup()
|
||||
{ |
||||
Serial.begin(115200); |
||||
|
||||
pinMode(D5, OUTPUT); |
||||
pinMode(D7, INPUT); |
||||
digitalWrite(D5, HIGH); |
||||
|
||||
Blinker.begin(/*auth,*/ ssid, pswd); |
||||
Button1.attach(button1_callback); |
||||
Button2.attach(button2_callback); |
||||
Button3.attach(button3_callback); |
||||
Button4.attach(button4_callback); |
||||
Slider1.attach(slider1_callback); |
||||
} |
||||
|
||||
//main loop function
|
||||
void loop()
|
||||
{ |
||||
Blinker.run(); |
||||
|
||||
if(a==1&&time2>=Blinker.time()) |
||||
{ |
||||
if((time2-Blinker.time())/60==0&&b<=(millis()-1000)){ Blinker.print("剩余秒数:");Blinker.print(time2-Blinker.time());b=millis();} |
||||
|
||||
if((time2-Blinker.time())>60&&b<=(millis()-15000)) |
||||
{ |
||||
Blinker.print("剩余分钟:"); |
||||
Blinker.print((time2-Blinker.time())/60); |
||||
b=millis(); |
||||
} |
||||
|
||||
} |
||||
|
||||
if(a==1&&time2<=Blinker.time()) |
||||
{ |
||||
delay(500); |
||||
Button4.print("加水结束!!"); |
||||
Blinker.notify("计时加水已结束!"); |
||||
|
||||
digitalWrite(D5, HIGH); |
||||
a=0; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue