//Visitors Counter and Automatic Room Light

#include<LiquidCrystal.h>

LiquidCrystal lcd(12,11,7,6,5,4);

#define in  2
#define out  3
//#define total  
#define Light 13
int count=0;
int total=0;

void setup()
{
  lcd.begin(16,2);
  lcd.print("VISITOR COUNTER");
  delay(2000);
  pinMode(in, INPUT);
  pinMode(out, INPUT);
  pinMode(Light, OUTPUT);
  pinMode(total,INPUT);
  lcd.clear();
  lcd.print("Person In Room:");
  lcd.setCursor(0,1);
  lcd.print(count);
  delay(1000);
  
}
void loop()
{  
  int in_value = digitalRead(in);
  int out_value = digitalRead(out);
  int total_value = digitalRead(in);

  if(in_value== LOW)
  
  {
    count++;
    total++;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
        
  }

  if(out_value == LOW)
  {
    count--;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
  }


  if(count <=0)
  {
   
    lcd.clear();
    digitalWrite(Light, LOW);
    lcd.clear();
    lcd.print("Nobody In Room");
    lcd.setCursor(0,1);
    lcd.print("Light Goes Down");
    delay(1000);
    lcd.clear();
    lcd.print("Total Entry Today");
    lcd.setCursor(0,1);
    lcd.print(total);
    delay(1000);
  }

  else
  {
    digitalWrite(Light,HIGH);
  }
}