|
|
|
@ -2,8 +2,24 @@ |
|
|
|
|
* this is the code for control unit in hallway |
|
|
|
|
*
|
|
|
|
|
* *****************************************************************/ |
|
|
|
|
// MQTT auth code
|
|
|
|
|
#define MQTT_AUTH "7e62353fa063" |
|
|
|
|
// MQTT auth code and WIFI
|
|
|
|
|
#define MQTT_AUTH_CODE "7e62353fa063" |
|
|
|
|
#define WIFI_SSID "yimian-iot" |
|
|
|
|
#define WIFI_PASSWD "1234567890." |
|
|
|
|
|
|
|
|
|
// Pins Log ID
|
|
|
|
|
#define W_DEVICE_ID "2" |
|
|
|
|
#define W_LIGHT_ID "L1" |
|
|
|
|
#define W_SWI_ID "S1" |
|
|
|
|
#define W_TEMP_ID "" |
|
|
|
|
#define W_HUM_ID "" |
|
|
|
|
#define W_TEL_ID "T" |
|
|
|
|
#define W_R1_ID "R1" |
|
|
|
|
#define W_R2_ID "R2" |
|
|
|
|
#define W_R3_ID "R3" |
|
|
|
|
#define W_R4_ID "R4" |
|
|
|
|
#define W_LED_ID "l1" |
|
|
|
|
#define W_BUZ_ID "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set as WIFI mode
|
|
|
|
@ -17,131 +33,318 @@ |
|
|
|
|
#define lightCtl D5 //Control the light
|
|
|
|
|
#define swiIn D4 // Pins for Check the switch state :: signal In
|
|
|
|
|
#define swiOut D8 // Pins for Check the switch state :: signal Out
|
|
|
|
|
#define rSnsr1 D6 // Pins for searching people
|
|
|
|
|
#define rSnsr2 D13 // Pins for searching people
|
|
|
|
|
#define rSnsr3 D1 |
|
|
|
|
#define rSnsr4 D2 |
|
|
|
|
#define uDoorOpenPin D12 // Pins for opening door
|
|
|
|
|
#define uDoorVoice D11 // Pins for connecting voice lines
|
|
|
|
|
#define uDoorTel D10 // Pins for detecting if Tel is on
|
|
|
|
|
#define led D3 |
|
|
|
|
|
|
|
|
|
// Parameter Define
|
|
|
|
|
#define SWI_TRY_TIMES 100 |
|
|
|
|
#define SWI_OK_TIMES 77 |
|
|
|
|
// Set wifi and MQTT config
|
|
|
|
|
char auth[] =
|
|
|
|
|
|
|
|
|
|
//announce keyname
|
|
|
|
|
BlinkerButton Button1("btn-abc"); |
|
|
|
|
BlinkerButton Button2("btn-on"); |
|
|
|
|
BlinkerButton Button3("btn-off"); |
|
|
|
|
// Parameter Define
|
|
|
|
|
#define SWI_TRY_TIMES 300 |
|
|
|
|
#define SWI_ACTION_DELAY 30 |
|
|
|
|
#define UDOOR_OPEN_DELAY_TIME 800 |
|
|
|
|
|
|
|
|
|
//declear var
|
|
|
|
|
int swi,swi1 ,i,a,timer,timer1,b,c= 0; |
|
|
|
|
|
|
|
|
|
// Set wifi and MQTT config
|
|
|
|
|
char auth[] = MQTT_AUTH_CODE; |
|
|
|
|
char ssid[] = WIFI_SSID; |
|
|
|
|
char pswd[] = WIFI_PASSWD; |
|
|
|
|
|
|
|
|
|
// load module
|
|
|
|
|
BlinkerButton wIoT("wIoT"); |
|
|
|
|
BlinkerButton lightCtlBtn("btn-light"); |
|
|
|
|
BlinkerButton uDoorOpenBtn("btn-uDoorOpen"); |
|
|
|
|
|
|
|
|
|
BlinkerText txtTel("tex-tel"); |
|
|
|
|
BlinkerText txtR1("tex-r1"); |
|
|
|
|
BlinkerText txtR2("tex-r2"); |
|
|
|
|
BlinkerText txtR3("tex-r3"); |
|
|
|
|
BlinkerText txtR4("tex-r4"); |
|
|
|
|
BlinkerText txtDir("tex-dir"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// declare global var
|
|
|
|
|
int swiStatus = 0; |
|
|
|
|
int uDoorTelStatus = 0; |
|
|
|
|
int rSnsr1Status,rSnsr2Status,rSnsr3Status,rSnsr4Status = 0; |
|
|
|
|
int isPeople = 0; |
|
|
|
|
|
|
|
|
|
/******** Custom Functions *********/ |
|
|
|
|
|
|
|
|
|
/*** LightCtl Functions ***/ |
|
|
|
|
// function for control light :: 0(shutdown),1(open),2(switch)
|
|
|
|
|
int light_ctl(int cmd) |
|
|
|
|
{ |
|
|
|
|
if(cmd == 0) |
|
|
|
|
{ |
|
|
|
|
digitalWrite(lightCtl, LOW); |
|
|
|
|
if(digitalRead(lightCtl) == LOW) {BLINKER_LOG("Run Funtion light_ctl :: light Shutdown");update_light_btn();return 1;} |
|
|
|
|
else {BLINKER_LOG("ERROR in Funtion light_ctl :: when light Shutdown");return 0;} |
|
|
|
|
} |
|
|
|
|
if(cmd == 1) |
|
|
|
|
{ |
|
|
|
|
digitalWrite(lightCtl, HIGH); |
|
|
|
|
if(digitalRead(lightCtl) == HIGH) {BLINKER_LOG("Run Funtion light_ctl :: light Open");update_light_btn();return 1;} |
|
|
|
|
else {BLINKER_LOG("ERROR in Funtion light_ctl :: when light Open");return 0;} |
|
|
|
|
} |
|
|
|
|
if(cmd == 2) |
|
|
|
|
{ |
|
|
|
|
int lightStatus = digitalRead(lightCtl); |
|
|
|
|
digitalWrite(lightCtl, !lightStatus); |
|
|
|
|
if(digitalRead(lightCtl) != lightStatus) {BLINKER_LOG("Run Funtion light_ctl :: light Switch");update_light_btn();return 1;} |
|
|
|
|
else {BLINKER_LOG("ERROR in Funtion light_ctl :: when light Switch");return 0;} |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//function for get light info :: ::return 0(shutdown),1(open)
|
|
|
|
|
int get_light_status() |
|
|
|
|
{ |
|
|
|
|
if(digitalRead(lightCtl) == LOW) return 0; |
|
|
|
|
else if (digitalRead(lightCtl == HIGH)) return 1; |
|
|
|
|
else return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// function for dealing with light error
|
|
|
|
|
int light_err() |
|
|
|
|
{ |
|
|
|
|
BLINKER_LOG("ERROR with LIGHTCTL!!!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//button1-function
|
|
|
|
|
void button1_callback(const String & state)
|
|
|
|
|
// function for update app button state
|
|
|
|
|
void update_light_btn() |
|
|
|
|
{ |
|
|
|
|
BLINKER_LOG("get button state: ", state); |
|
|
|
|
if(digitalRead(D5)){ Button1.print("灯正亮!");}else{ Button1.print("灯未亮!");} |
|
|
|
|
digitalWrite(D5,LOW); |
|
|
|
|
Button1.print("正在重置!"); |
|
|
|
|
for(i=10;i>0;i--) |
|
|
|
|
{ |
|
|
|
|
Blinker.print(i); |
|
|
|
|
digitalWrite(D6,LOW);digitalWrite(D13,LOW); |
|
|
|
|
digitalRead(D6);digitalRead(D13); |
|
|
|
|
delay(1000); |
|
|
|
|
} |
|
|
|
|
a=0; |
|
|
|
|
Button1.print("重置完成!"); |
|
|
|
|
timer1=Blinker.time()-249; |
|
|
|
|
if(digitalRead(D5)){ Button1.print("灯已打开!");}else{ Button1.print("灯已关闭!");} |
|
|
|
|
if(digitalRead(lightCtl) == HIGH) |
|
|
|
|
{ |
|
|
|
|
lightCtlBtn.icon("fas fa-lightbulb"); |
|
|
|
|
lightCtlBtn.color("#00CD00"); |
|
|
|
|
lightCtlBtn.text("戳我关灯~","关灯啦~"); |
|
|
|
|
lightCtlBtn.print("on"); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
lightCtlBtn.icon("far fa-lightbulb"); |
|
|
|
|
lightCtlBtn.color("#FF0000"); |
|
|
|
|
lightCtlBtn.text("戳我开灯~","戳我开灯~"); |
|
|
|
|
lightCtlBtn.print("off"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** Swi Functions ***/ |
|
|
|
|
// function for judging swi state :: ::return 0(off),1(on),-1(error)
|
|
|
|
|
int get_swi_status() |
|
|
|
|
{ |
|
|
|
|
int swiCount = 0; |
|
|
|
|
int swiEff = 0; |
|
|
|
|
for(swiCount = 0; swiCount < SWI_TRY_TIMES; swiCount++) |
|
|
|
|
{ |
|
|
|
|
digitalWrite(swiOut, HIGH); |
|
|
|
|
//Blinker.delay(1);
|
|
|
|
|
if(digitalRead(swiIn) == HIGH) swiEff++; |
|
|
|
|
digitalWrite(swiOut, LOW); |
|
|
|
|
//Blinker.delay(1);
|
|
|
|
|
if(digitalRead(swiIn) == LOW) swiEff++; |
|
|
|
|
swiEff--; |
|
|
|
|
} |
|
|
|
|
BLINKER_LOG("Parameter in get_swi_status :: swiEff = ",swiEff); |
|
|
|
|
if(swiEff == SWI_TRY_TIMES) return 1; |
|
|
|
|
else if(swiEff == 0) return 0; |
|
|
|
|
else return swiStatus; |
|
|
|
|
} |
|
|
|
|
/*** rSnsr functions ***/ |
|
|
|
|
//
|
|
|
|
|
int is_People() |
|
|
|
|
{ |
|
|
|
|
int rCnt=0; |
|
|
|
|
int change=0; |
|
|
|
|
int t_rSnsr1Status,t_rSnsr2Status,t_rSnsr3Status,t_rSnsr4Status = 0; |
|
|
|
|
|
|
|
|
|
t_rSnsr1Status = digitalRead(rSnsr1); |
|
|
|
|
t_rSnsr2Status = digitalRead(rSnsr2); |
|
|
|
|
t_rSnsr3Status = digitalRead(rSnsr3); |
|
|
|
|
t_rSnsr4Status = digitalRead(rSnsr4); |
|
|
|
|
|
|
|
|
|
if(t_rSnsr1Status == HIGH) {if(rSnsr1Status != t_rSnsr1Status)change=1;rCnt++;} |
|
|
|
|
else if(rSnsr1Status != t_rSnsr1Status)change=1; |
|
|
|
|
if(t_rSnsr2Status == HIGH) {if(rSnsr2Status != t_rSnsr2Status)change=1;rCnt++;} |
|
|
|
|
else if(rSnsr2Status != t_rSnsr2Status)change=1; |
|
|
|
|
if(t_rSnsr3Status == HIGH) {if(rSnsr3Status != t_rSnsr3Status)change=1;rCnt++;} |
|
|
|
|
else if(rSnsr3Status != t_rSnsr3Status)change=1; |
|
|
|
|
if(t_rSnsr4Status == HIGH) {if(rSnsr4Status != t_rSnsr4Status)change=1;rCnt++;} |
|
|
|
|
else if(rSnsr4Status != t_rSnsr4Status)change=1; |
|
|
|
|
|
|
|
|
|
rSnsr1Status = t_rSnsr1Status; |
|
|
|
|
rSnsr2Status = t_rSnsr2Status; |
|
|
|
|
rSnsr3Status = t_rSnsr3Status; |
|
|
|
|
rSnsr4Status = t_rSnsr4Status; |
|
|
|
|
|
|
|
|
|
if(change) rSnsr_data(); |
|
|
|
|
|
|
|
|
|
if(rCnt >= 2) return 1; |
|
|
|
|
else return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//button2-function
|
|
|
|
|
void button2_callback(const String & state)
|
|
|
|
|
void rSnsr_data() |
|
|
|
|
{ |
|
|
|
|
BLINKER_LOG("get button state: ", state); |
|
|
|
|
a=1; |
|
|
|
|
digitalWrite(D5,HIGH); |
|
|
|
|
if(digitalRead(D5)){ Button1.print("灯已打开!");}else{ Button1.print("灯已关闭!");} |
|
|
|
|
timer=Blinker.time(); |
|
|
|
|
}
|
|
|
|
|
if(rSnsr1Status == HIGH) txtR1.print("r1","有人经过"); |
|
|
|
|
else txtR1.print("r1","无人"); |
|
|
|
|
if(rSnsr2Status == HIGH) txtR2.print("r2","有人经过"); |
|
|
|
|
else txtR2.print("r2","无人"); |
|
|
|
|
if(rSnsr3Status == HIGH) txtR3.print("r3","有人经过"); |
|
|
|
|
else txtR3.print("r3","无人"); |
|
|
|
|
if(rSnsr4Status == HIGH) txtR4.print("r4","有人经过"); |
|
|
|
|
else txtR4.print("r4","无人"); |
|
|
|
|
if((rSnsr1Status||rSnsr2Status)&&!(rSnsr3Status||rSnsr4Status)) txtDir.print("方向","出"); |
|
|
|
|
if(!(rSnsr1Status||rSnsr2Status)&&(rSnsr3Status||rSnsr4Status)) txtDir.print("方向","进"); |
|
|
|
|
if(!rSnsr1Status&&rSnsr2Status&&!rSnsr3Status&&rSnsr4Status) txtDir.print("方向","未知"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** uDoor functions ***/ |
|
|
|
|
// function for opening the unit door
|
|
|
|
|
void open_uDoor() |
|
|
|
|
{ |
|
|
|
|
digitalWrite(uDoorOpenPin, HIGH); |
|
|
|
|
Blinker.vibrate(); |
|
|
|
|
txtTel.print("门铃","单元门打开!!"); |
|
|
|
|
Blinker.delay(UDOOR_OPEN_DELAY_TIME); |
|
|
|
|
digitalWrite(uDoorOpenPin, LOW); |
|
|
|
|
BLINKER_LOG("open_uDoor :: Under Door Opened!!"); |
|
|
|
|
} |
|
|
|
|
// function for controling the unit Door Voice :: 0(disconnected),1(connected)
|
|
|
|
|
void voice_uDoor(int cmd) |
|
|
|
|
{ |
|
|
|
|
if(cmd == 0) |
|
|
|
|
digitalWrite(uDoorVoice, LOW); |
|
|
|
|
if(cmd == 1) |
|
|
|
|
digitalWrite(uDoorVoice, HIGH); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//button3-function
|
|
|
|
|
void button3_callback(const String & state)
|
|
|
|
|
void uDoor_tel_mode() |
|
|
|
|
{ |
|
|
|
|
BLINKER_LOG("get button state: ", state); |
|
|
|
|
a=1; |
|
|
|
|
digitalWrite(D5,LOW); |
|
|
|
|
if(digitalRead(D5)){ Button1.print("灯已打开!");}else{ Button1.print("灯已关闭!");} |
|
|
|
|
timer=Blinker.time(); |
|
|
|
|
}
|
|
|
|
|
if(digitalRead(uDoorTel) == HIGH) |
|
|
|
|
{voice_uDoor(1);if(digitalRead(uDoorTel) != uDoorTelStatus)txtTel.print("门铃","麦克风已接通!");} |
|
|
|
|
else
|
|
|
|
|
{voice_uDoor(0);if(digitalRead(uDoorTel) != uDoorTelStatus)txtTel.print("门铃","未接通");} |
|
|
|
|
uDoorTelStatus = digitalRead(uDoorTel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void uDoor_data() |
|
|
|
|
{ |
|
|
|
|
if(digitalRead(uDoorTel) == HIGH)txtTel.print("门铃","麦克风已接通!"); |
|
|
|
|
if(digitalRead(uDoorTel) == LOW)txtTel.print("门铃","未接通"); |
|
|
|
|
} |
|
|
|
|
/******** Blinker Attached Function *********/ |
|
|
|
|
//
|
|
|
|
|
void lightCtlBtn_callback(const String & state) |
|
|
|
|
{ |
|
|
|
|
BLINKER_LOG("lightCtlBtn :: get button state: ", state); |
|
|
|
|
|
|
|
|
|
if (state == BLINKER_CMD_BUTTON_TAP) { |
|
|
|
|
BLINKER_LOG("Button tap!"); |
|
|
|
|
if(!light_ctl(2)) light_err(); |
|
|
|
|
} |
|
|
|
|
else if (state == BLINKER_CMD_ON) { |
|
|
|
|
BLINKER_LOG("Toggle on!"); |
|
|
|
|
if(!light_ctl(1)) light_err(); |
|
|
|
|
} |
|
|
|
|
else if (state == BLINKER_CMD_OFF) { |
|
|
|
|
BLINKER_LOG("Toggle off!"); |
|
|
|
|
if(!light_ctl(0)) light_err(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//main setup function
|
|
|
|
|
void setup()
|
|
|
|
|
void uDoorOpenBtn_callback(const String & state) |
|
|
|
|
{ |
|
|
|
|
Serial.begin(115200); |
|
|
|
|
|
|
|
|
|
pinMode(D5, OUTPUT); //control the light
|
|
|
|
|
pinMode(D6, INPUT); //sensor1
|
|
|
|
|
pinMode(D13, INPUT); //sensor2
|
|
|
|
|
//D4&D8 are used for checking the switch state
|
|
|
|
|
pinMode(D4, INPUT); |
|
|
|
|
pinMode(D8, OUTPUT); |
|
|
|
|
|
|
|
|
|
//set the light paraperation
|
|
|
|
|
digitalWrite(D5, HIGH); |
|
|
|
|
open_uDoor(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//connect to WIFI
|
|
|
|
|
Blinker.begin(auth ,ssid, pswd); |
|
|
|
|
|
|
|
|
|
//set interrupt
|
|
|
|
|
Button1.attach(button1_callback); |
|
|
|
|
Button2.attach(button2_callback); |
|
|
|
|
Button3.attach(button3_callback); |
|
|
|
|
/******* Heartbeat Function ********/ |
|
|
|
|
// Heartbeat for Blinker app
|
|
|
|
|
void heartbeat_app() |
|
|
|
|
{ |
|
|
|
|
update_light_btn(); |
|
|
|
|
rSnsr_data(); |
|
|
|
|
uDoor_data(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Heartbeat for wIoT
|
|
|
|
|
void heartbeat(const String & state) |
|
|
|
|
{ |
|
|
|
|
Blinker.print(W_LIGHT_ID,digitalRead(lightCtl)); |
|
|
|
|
Blinker.print(W_SWI_ID,get_swi_status()); |
|
|
|
|
Blinker.print(W_TEL_ID,digitalRead(uDoorTel)); |
|
|
|
|
Blinker.print(W_R1_ID,digitalRead(rSnsr1)); |
|
|
|
|
Blinker.print(W_R2_ID,digitalRead(rSnsr2)); |
|
|
|
|
Blinker.print(W_R3_ID,digitalRead(rSnsr3)); |
|
|
|
|
Blinker.print(W_R4_ID,digitalRead(rSnsr4)); |
|
|
|
|
Blinker.print(W_LED_ID,digitalRead(led)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/******* Arduino Setup Funstion *******/ |
|
|
|
|
void setup() |
|
|
|
|
{ |
|
|
|
|
// Serial ini
|
|
|
|
|
Serial.begin(115200); |
|
|
|
|
BLINKER_DEBUG.stream(Serial); |
|
|
|
|
|
|
|
|
|
// Pins state declare
|
|
|
|
|
pinMode(lightCtl, OUTPUT); |
|
|
|
|
pinMode(swiIn, INPUT); |
|
|
|
|
pinMode(swiOut, OUTPUT); |
|
|
|
|
pinMode(uDoorOpenPin, OUTPUT); |
|
|
|
|
pinMode(uDoorVoice, OUTPUT); |
|
|
|
|
pinMode(uDoorTel, INPUT); |
|
|
|
|
pinMode(rSnsr1, INPUT); |
|
|
|
|
pinMode(rSnsr2, INPUT); |
|
|
|
|
pinMode(rSnsr3, INPUT); |
|
|
|
|
pinMode(rSnsr4, INPUT); |
|
|
|
|
pinMode(led, OUTPUT); |
|
|
|
|
|
|
|
|
|
// Pins state ini
|
|
|
|
|
digitalWrite(lightCtl, HIGH); |
|
|
|
|
|
|
|
|
|
// swi ini
|
|
|
|
|
swiStatus = get_swi_status(); |
|
|
|
|
|
|
|
|
|
// uDoor Tel ini
|
|
|
|
|
uDoorTelStatus = digitalRead(uDoorTel); |
|
|
|
|
|
|
|
|
|
// rSnsr ini
|
|
|
|
|
rSnsr1Status = digitalRead(rSnsr1); |
|
|
|
|
rSnsr2Status = digitalRead(rSnsr2); |
|
|
|
|
rSnsr3Status = digitalRead(rSnsr3); |
|
|
|
|
rSnsr4Status = digitalRead(rSnsr4); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Blinker ini
|
|
|
|
|
Blinker.begin(auth, ssid, pswd); |
|
|
|
|
|
|
|
|
|
// Blinker attached Functions
|
|
|
|
|
wIoT.attach(heartbeat); |
|
|
|
|
lightCtlBtn.attach(lightCtlBtn_callback); |
|
|
|
|
uDoorOpenBtn.attach(uDoorOpenBtn_callback); |
|
|
|
|
|
|
|
|
|
// Blinker attached Heartbeat
|
|
|
|
|
Blinker.attachHeartbeat(heartbeat_app); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//main loop function
|
|
|
|
|
/******** Arduino Main loop Function********/ |
|
|
|
|
void loop() { |
|
|
|
|
// Active Blinker
|
|
|
|
|
Blinker.run(); |
|
|
|
|
|
|
|
|
|
//get time info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//judge the switch state
|
|
|
|
|
swi1=swi; |
|
|
|
|
swi=0; |
|
|
|
|
for(i=0;i<2;i++) |
|
|
|
|
{ |
|
|
|
|
//change D8 state
|
|
|
|
|
digitalWrite(D8,!digitalRead(D8)); |
|
|
|
|
if(digitalRead(D4)!=digitalRead(D8)){ swi++;} |
|
|
|
|
} |
|
|
|
|
// Switch Ctl
|
|
|
|
|
if(swiStatus != get_swi_status()) {Blinker.delay(SWI_ACTION_DELAY);if(swiStatus != get_swi_status()){light_ctl(2);swiStatus = get_swi_status();}} |
|
|
|
|
|
|
|
|
|
BLINKER_LOG("get slider value: ", swi); |
|
|
|
|
if(swi!=swi1){digitalWrite(D5,!digitalRead(D5));a=1;timer=Blinker.time();Blinker.print("已切换至手动控制!");} |
|
|
|
|
if(timer==(Blinker.time()-300)){a=0;Blinker.print("手动控制结束!");} |
|
|
|
|
BLINKER_LOG("get slhgggggggggggider value: ",digitalRead(D5) ); |
|
|
|
|
//get sensor info
|
|
|
|
|
BLINKER_LOG("get sensor1: ", digitalRead(D13)); |
|
|
|
|
BLINKER_LOG("get sensor2: ", digitalRead(D6)); |
|
|
|
|
BLINKER_LOG("a= ", a); |
|
|
|
|
|
|
|
|
|
//if people light on
|
|
|
|
|
if(digitalRead(D6)==1&&digitalRead(D13)==1&&a!=1){ Blinker.print("探测到人"); if(Blinker.hour()<=7||Blinker.hour()>=17){ digitalWrite(D5,HIGH);Blinker.print("灯已打开!");timer1=Blinker.time();}}else{if(a!=1&&timer1==(Blinker.time()-250)){digitalWrite(D5,LOW);Blinker.print("未探测到人,灯已关闭!"); Button1.print("正在重置!"); |
|
|
|
|
for(i=10;i>0;i--) |
|
|
|
|
{ |
|
|
|
|
Blinker.print(i); |
|
|
|
|
|
|
|
|
|
digitalRead(D6);digitalRead(D13); |
|
|
|
|
delay(1000); |
|
|
|
|
} |
|
|
|
|
Button1.print("重置完成!");}} |
|
|
|
|
// Tel Ctl
|
|
|
|
|
uDoor_tel_mode(); |
|
|
|
|
|
|
|
|
|
// If people Light
|
|
|
|
|
if(is_People()&&is_People()!=isPeople) light_ctl(1); |
|
|
|
|
isPeople = is_People(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|