add light sensor p2
This commit is contained in:
parent
65daad87ac
commit
05616e8868
|
@ -67,10 +67,19 @@
|
||||||
#define relay_2 6 //6 // Set Relay 1 Pin
|
#define relay_2 6 //6 // Set Relay 1 Pin
|
||||||
#define button_2 8 // button exit
|
#define button_2 8 // button exit
|
||||||
|
|
||||||
#define wipeB A0 // Button pin for WipeMode
|
|
||||||
|
|
||||||
#define Light A1 // Led tro sang camera
|
#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;
|
||||||
int stt_old;
|
int stt_old;
|
||||||
|
@ -95,14 +104,14 @@ void setup()
|
||||||
pinMode(13, OUTPUT);
|
pinMode(13, OUTPUT);
|
||||||
pinMode(Light, OUTPUT);
|
pinMode(Light, OUTPUT);
|
||||||
digitalWrite(13, LOW);
|
digitalWrite(13, LOW);
|
||||||
|
|
||||||
pinMode(ledView, OUTPUT);
|
pinMode(ledView, OUTPUT);
|
||||||
pinMode(wipeB, INPUT_PULLUP); // Enable pin's pull up resistor
|
pinMode(ss, INPUT);
|
||||||
pinMode(relay, OUTPUT);
|
pinMode(relay, OUTPUT);
|
||||||
pinMode(relay_2, OUTPUT);
|
pinMode(relay_2, OUTPUT);
|
||||||
pinMode(button,INPUT);
|
pinMode(button, INPUT);
|
||||||
pinMode(button_2,INPUT);
|
pinMode(button_2, INPUT);
|
||||||
|
|
||||||
digitalWrite(relay, HIGH); // Make sure door is locked
|
digitalWrite(relay, HIGH); // Make sure door is locked
|
||||||
digitalWrite(relay_2, HIGH); // Make sure door is locked
|
digitalWrite(relay_2, HIGH); // Make sure door is locked
|
||||||
digitalWrite(Light, LOW);
|
digitalWrite(Light, LOW);
|
||||||
|
@ -113,9 +122,10 @@ void setup()
|
||||||
///////////////////////////////////////// Main Loop ///////////////////////////////////
|
///////////////////////////////////////// Main Loop ///////////////////////////////////
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
ReadButton();
|
ReadLightSS();
|
||||||
SerialRead();
|
ReadButton();
|
||||||
CheckButton();
|
SerialRead();
|
||||||
|
CheckButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////// Access Granted ///////////////////////////////////
|
///////////////////////////////////////// Access Granted ///////////////////////////////////
|
||||||
|
@ -167,7 +177,7 @@ void ReadButton()
|
||||||
{
|
{
|
||||||
relay_stt = false;
|
relay_stt = false;
|
||||||
}
|
}
|
||||||
if (stt_2 == 0 && stt_old_2 == 1)
|
if (stt_2 == 0 && stt_old_2 == 1)
|
||||||
{
|
{
|
||||||
//Serial.println("Button 2 press");
|
//Serial.println("Button 2 press");
|
||||||
relay_stt_2 = true;
|
relay_stt_2 = true;
|
||||||
|
@ -176,10 +186,49 @@ void ReadButton()
|
||||||
{
|
{
|
||||||
relay_stt_2 = false;
|
relay_stt_2 = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
stt_old = stt;
|
stt_old = stt;
|
||||||
stt_old_2 = stt_2;
|
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();
|
ClearSerialdata();
|
||||||
|
|
||||||
} else if (input == "4") {
|
} else if (input == "4") {
|
||||||
|
|
||||||
if (Light_stt == true) {
|
if (Light_stt == true) {
|
||||||
TurnOff_Light();
|
TurnOff_Light();
|
||||||
|
|
||||||
}
|
}
|
||||||
Serial.println("open_4");
|
Serial.println("open_4");
|
||||||
ClearSerialdata();
|
ClearSerialdata();
|
||||||
}
|
}
|
||||||
else if (input == "1")
|
else if (input == "1")
|
||||||
{
|
{
|
||||||
|
|
||||||
if (relay_stt == false)
|
if (relay_stt == false)
|
||||||
{
|
{
|
||||||
relay_stt = true;
|
relay_stt = true;
|
||||||
|
@ -219,9 +268,9 @@ void SerialRead()
|
||||||
}
|
}
|
||||||
Serial.println("open_1");
|
Serial.println("open_1");
|
||||||
ClearSerialdata();
|
ClearSerialdata();
|
||||||
}else if (input == "2")
|
} else if (input == "2")
|
||||||
{
|
{
|
||||||
|
|
||||||
if (relay_stt_2 == false)
|
if (relay_stt_2 == false)
|
||||||
{
|
{
|
||||||
relay_stt_2 = true;
|
relay_stt_2 = true;
|
||||||
|
@ -229,8 +278,11 @@ void SerialRead()
|
||||||
}
|
}
|
||||||
Serial.println("open_2");
|
Serial.println("open_2");
|
||||||
ClearSerialdata();
|
ClearSerialdata();
|
||||||
}
|
} else if (input == "recv_bf")
|
||||||
else
|
{
|
||||||
|
stt_msg = false;
|
||||||
|
ClearSerialdata();
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
digitalWrite(13, LOW);
|
digitalWrite(13, LOW);
|
||||||
}
|
}
|
||||||
|
@ -259,7 +311,7 @@ void CheckButton()
|
||||||
relay_stt = false;
|
relay_stt = false;
|
||||||
}
|
}
|
||||||
//-------------------------
|
//-------------------------
|
||||||
if (relay_stt_2 == true)
|
if (relay_stt_2 == true)
|
||||||
{
|
{
|
||||||
granted_2(4000); // Open the door lock for 300 ms
|
granted_2(4000); // Open the door lock for 300 ms
|
||||||
relay_stt_2 = false;
|
relay_stt_2 = false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user