
int inputSwitchPin = 2;
int lastState;

long timeLastPressed;
long debouncePeriod = 100;

int houseState;
long doormatUnblockAt;
long doormatDelayPeriod = 2000;
int blockSteps;

void setup() {
  Serial.begin(9600);
  pinMode(inputSwitchPin, INPUT);     // declare pushbutton as input
  lastState = digitalRead(inputSwitchPin);
  timeLastPressed = millis();
  blockSteps = 0;
  houseState = 0;
}

void loop() {
  int pinState = digitalRead(inputSwitchPin);
  
  if (pinState != lastState && millis() - timeLastPressed > debouncePeriod) {
     if (pinState == 0) {  // i.e., pressed
       if (!blockSteps) {
         houseState = 1-houseState;
         blockSteps = 1;
         Serial.print(houseState?"1":"0");
       }
       doormatUnblockAt = millis() + doormatDelayPeriod;
     }
    timeLastPressed = millis();
    lastState = pinState;
  }
  
 
  if (millis() > doormatUnblockAt) {
    blockSteps = 0;
  }
}


