#define SWout 4
#define SWin 2
int lastState1 = HIGH; int lastState2 = HIGH; int Nop; long Tin1=0; long LTin1=0;
long Tout1=0; long LTout1=0; long Tin2=0; long Tout2=0; unsigned long Stauts1;
unsigned long LastStauts1;
void setup() {
Serial.begin(115200);
pinMode(SWout, INPUT_PULLUP);
pinMode(SWin, INPUT_PULLUP);
}
void loop()
{
int value1 = digitalRead((SWin));
if (lastState1 != value1)
{
lastState1 = value1;
if (value1 == LOW)
{
Serial.println(" pressed_1");
Tin1=millis();
Serial.print("Tin1 first time during in = ");
Serial.println(Tin1);
}
}
int value2 = digitalRead((SWout));
if (lastState2 != value2)
{
lastState2 = value2;
if (value2 == LOW)
{
Serial.println(" pressed_2");
Tout1=millis();
Serial.print("Tout1 first time during out = ");
Serial.println(Tout1);
}
}
if (LastStauts1 != (Tin1-Tout1))
{
LastStauts1 = (Tin1-Tout1);
if((Tin1-Tout1)<0 )
{
Nop++;
Serial.print("No. of Person in Room =");
Serial.println(Nop);
}
}
//Tin1=Tin2=Tout1=Tout2=0;
}