From 05616e886864c52d5908b5c780b8d2a15e74be94 Mon Sep 17 00:00:00 2001 From: haimd Date: Wed, 9 Jun 2021 10:24:59 +0700 Subject: [PATCH] add light sensor p2 --- Lock.rar | Bin 0 -> 2057 bytes Lock/Lock.ino | 92 +++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 72 insertions(+), 20 deletions(-) create mode 100644 Lock.rar diff --git a/Lock.rar b/Lock.rar new file mode 100644 index 0000000000000000000000000000000000000000..a8331149408497aa4d937f6800cbe8f9165771f7 GIT binary patch literal 2057 zcmV+k2=@0ed0s2a*Rc1w%74Pc>#={Q~$o*`QkGc2?SQ zOVKxA4mPBWSJE1C&CoP!3N)LDR}x_~oZGd}c_~ai2_jNYrdhOagecmC=SL279KvMr z%=jlWhYn{r0R>|GFT(J8Ucqf%QQ#d>^!gIb2Toh+*03xUx)!7T@DDkMwC&7fD?~%Z zrW`Zpw88jG1@tEaO$ziTPs)#Jw^?io-z3u04c)=ga!YCR2KJ1(mqj_%NATm^;mtbS zu=_vi9+F|n1`?X6Wj=kF@=;ohl~Ef0pPkFScOsoSdafs*W;~iD6sESBn)Mk>Wc!J( z9+jI?Yv&tjlk$c+r@26v*XhDVOp{-5cl^Ik8J{>PQ8*0sfRf)qa0<0TkiN)TKnRmPjv=0B-UfZMkoXxy=qe2H!>EvqN8V_ujGD-+ z-M4P-%r&lEu&NAUH4GqBKUaF?ljr9bO`eXJU^EQu%}|KkwG)Ff+X1O0__{G@J`05L z>0qdG=L-AIf+j#k1%j4R1nkQDB_&o+X3vK3qE>RKsb)4;IdB;)#EQ8bzAA5R(hTZ41 z+RX8iE23^|-4?7%1f8(9ztkG+?}fxza5u;eII_8j2{EWyD=Xwy&mkj>@QcU2oY|nW zAfyWZ?#4lVx*r}obkC*PYyt>fuk@OUkVFf;-OqtsMp+GOybtz@^>704-1j;TAZ=RE zH~Wt0LFRHz&>O8;tXV+r{B9{sNJ_tJIKHT(Zml@0Vh$=n=je5I-erSYk7wtJ76;u2 ziN?=r*sU~YB&M#ngvLRY7vEDZjXer=8#g@b?48L#GafylHa&z++U&4g!TApLPzwEe zrydZvb1zsX;f)@r_eBut`co18>TH{pF6h5Ws!`W0jFSZfp(c|UL_wV)c++pR!j5KS z+ztSif?)+*PBzAUojTuUMo(DD9Xb?JDho3RUS5mQ?ZdE3#jj3894c;c43*9Q(jt|b z{M1JxIX|{q=jY_HSsL&?fla(Pm;#?Yh(p>*>lt; ziX&2RlIK|U0BEdxoaPRM&t(Q@dOptJL@aT7z@6t0jmIJ)+6E|rlbm+Wwy{aFN)K_67o%(Kk(tO(!hQ{)WCHwvE~H581v6o3I* z{~l^#^Nm>Nf;Y~Cef_NmJrp8*7tpw7CqF@NZc$T43Ky+`7?_et{DT{=S5t2Soey91 z@2`JTFwD0Z(`5G%Yr2Glf=)y~0N$&;zaFS_NL_gF=@bD-*5+~th7FIV4wB~yBy7mKDu z(|fIX;_U_S^qqP{-1sA-BiKeQ2`K>`2ck6>QBE3hagB7GpFP^j9H^6wdZ2t=+4Z;K zpMaD1hS&7Zm(X`-%vQUHP!ZSv!KuyC>LE52JftWnubV=wDtWXlo5(3X0Dv_jHy#25 n3jhTG5C8xG0Du4h1Wa#ZYYGDb&{U4%O6t}D9d}ky0|f*CR~^2` literal 0 HcmV?d00001 diff --git a/Lock/Lock.ino b/Lock/Lock.ino index 8e646f4..0fc8409 100644 --- a/Lock/Lock.ino +++ b/Lock/Lock.ino @@ -67,10 +67,19 @@ #define relay_2 6 //6 // Set Relay 1 Pin #define button_2 8 // button exit -#define wipeB A0 // Button pin for WipeMode + #define Light A1 // Led tro sang camera +//------------------------ +#define ss A0 +int stt_ss; +int stt_old_ss; +String input_ss; +int th = 1023; // ngưỡng +int time_get = 250; + +//------------------------ int stt; int stt_old; @@ -95,14 +104,14 @@ void setup() pinMode(13, OUTPUT); pinMode(Light, OUTPUT); digitalWrite(13, LOW); - + pinMode(ledView, OUTPUT); - pinMode(wipeB, INPUT_PULLUP); // Enable pin's pull up resistor + pinMode(ss, INPUT); pinMode(relay, OUTPUT); pinMode(relay_2, OUTPUT); - pinMode(button,INPUT); - pinMode(button_2,INPUT); - + pinMode(button, INPUT); + pinMode(button_2, INPUT); + digitalWrite(relay, HIGH); // Make sure door is locked digitalWrite(relay_2, HIGH); // Make sure door is locked digitalWrite(Light, LOW); @@ -113,9 +122,10 @@ void setup() ///////////////////////////////////////// Main Loop /////////////////////////////////// void loop() { - ReadButton(); - SerialRead(); - CheckButton(); + ReadLightSS(); + ReadButton(); + SerialRead(); + CheckButton(); } ///////////////////////////////////////// Access Granted /////////////////////////////////// @@ -167,7 +177,7 @@ void ReadButton() { relay_stt = false; } - if (stt_2 == 0 && stt_old_2 == 1) + if (stt_2 == 0 && stt_old_2 == 1) { //Serial.println("Button 2 press"); relay_stt_2 = true; @@ -176,10 +186,49 @@ void ReadButton() { relay_stt_2 = false; } - + stt_old = stt; stt_old_2 = stt_2; } +//Read Light Sensor +bool stt_msg = false; +void ReadLightSS() +{ + // stt_ss = digitalRead(ss); + int val = analogRead(A0); + if (val > th) { + delay (time_get); + int val = analogRead(A0); + if (val > th) { + stt_ss = 1; + } else { + stt_ss = 0; + } + } else { + stt_ss = 0; + } + // + if (stt_ss == 1 && stt_old_ss == 0) + { + stt_msg = true; // bật cờ gửi tín hiệu cho engine bật ads + + Light_stt = !Light_stt; + if (Light_stt == 1) { + TurnOn_Light(); + // Serial.println("Light sensor press ON"); + } + else { + TurnOff_Light(); + // Serial.println("Light sensor press OFF"); + } + + } + if (stt_msg == true){ + Serial.println("open_bf"); + ClearSerialdata() + } + stt_old_ss = stt_ss; +} @@ -201,17 +250,17 @@ void SerialRead() ClearSerialdata(); } else if (input == "4") { - + if (Light_stt == true) { TurnOff_Light(); - + } - Serial.println("open_4"); + Serial.println("open_4"); ClearSerialdata(); } else if (input == "1") { - + if (relay_stt == false) { relay_stt = true; @@ -219,9 +268,9 @@ void SerialRead() } Serial.println("open_1"); ClearSerialdata(); - }else if (input == "2") + } else if (input == "2") { - + if (relay_stt_2 == false) { relay_stt_2 = true; @@ -229,8 +278,11 @@ void SerialRead() } Serial.println("open_2"); ClearSerialdata(); - } - else + } else if (input == "recv_bf") + { + stt_msg = false; + ClearSerialdata(); + } else { digitalWrite(13, LOW); } @@ -259,7 +311,7 @@ void CheckButton() relay_stt = false; } //------------------------- - if (relay_stt_2 == true) + if (relay_stt_2 == true) { granted_2(4000); // Open the door lock for 300 ms relay_stt_2 = false;