#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <TimeOut.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
//////////
//GATE///
/////////
//set pin d12 as the input pin
const int gateSensor = 12;
bool showed = false;
//buzzer pins
const int buzzer = 11;
//timeout
TimeOut timeout;
void function(){
if(showed == true)
{
lcd.clear();
lcd.backlight();
}
return;
}
void setup() {
//lcd.begin(16,2);
lcd.init();
lcd.backlight();
lcd.clear();
//lcd.print("hello, world!");
//set the pin d12 as the inputPULLUP pin
pinMode(gateSensor, INPUT_PULLUP);
//control pins
Serial.begin(9600);
Serial.print("START");
}
void loop() {
Serial.print(digitalRead(gateSensor));
if(digitalRead(gateSensor) == LOW){
if(showed == false){
lcd.clear();
lcd.print("Gate is CLOSE");
showed = true;
timeout.timeOut(3000, function);
}
}
else{
if(showed == true){
lcd.clear();
lcd.print("Gate is OPEN");
showed = false;
tone(11, 262, 2000); // Plays 262Hz tone for 0.250 seconds
}
}
TimeOut::handler();
delay(200);
}