const int buzzer = 10;
int interruptPin = 3;
int digitalPin = 9;
volatile bool state = false;
int first = 1;



void setup()
{
  Serial.begin(9600);
  pinMode(interruptPin, INPUT_PULLUP);
  pinMode(digitalPin, INPUT_PULLUP);
  pinMode(buzzer, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
  Serial.println("System on Standby");
}

void blink()
{
  if(first)
  {
  state = true;
  digitalWrite(buzzer, HIGH);
  Serial.println("Piezo Buzzer On");
  first=0;
  }
}


void loop()
{
  int hi = digitalRead(digitalPin);
  int bye = digitalRead(interruptPin);

  if (hi == LOW)
  {
    if (!state)
    {
      state = true;
      digitalWrite(buzzer, HIGH);
      Serial.println("Piezo Buzzer On from Idle State");
      delay(1000);
      first=1;
    }

    else
    {
      state = false;
      digitalWrite(buzzer, LOW);
      Serial.println("Piezo Buzzer OFF. System on Standby");
      delay(1000);
      first=1;
    }
  }

}