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 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;
|
||||
|
@ -97,11 +106,11 @@ void setup()
|
|||
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
|
||||
|
@ -113,6 +122,7 @@ void setup()
|
|||
///////////////////////////////////////// Main Loop ///////////////////////////////////
|
||||
void loop()
|
||||
{
|
||||
ReadLightSS();
|
||||
ReadButton();
|
||||
SerialRead();
|
||||
CheckButton();
|
||||
|
@ -180,6 +190,45 @@ void ReadButton()
|
|||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -219,7 +268,7 @@ void SerialRead()
|
|||
}
|
||||
Serial.println("open_1");
|
||||
ClearSerialdata();
|
||||
}else if (input == "2")
|
||||
} else if (input == "2")
|
||||
{
|
||||
|
||||
if (relay_stt_2 == false)
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user