bool doorOpen = false;
bool doorAlarmActiveted =false;
void setup() {
// put your setup code here, to run once:
pinMode(5, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
doorOpen = digitalRead(5);
if (doorOpen)
{
if(not doorAlarmActiveted) // alarm eka ekaparak wath wdune(print une ) nathnam
{
Serial.println("Alarm door opened");
doorAlarmActiveted = true;
delay(500); // to avoid repeating due to switch bounce
}
else {} // no need to activate alarm if alarm activated once
}
else { // if door closed //if alarm activated no need to do anything , but need to reset alarm activated Variable to false when door closed.
if(doorAlarmActiveted) // when door closed reset elarm activated variable to false.
{
doorAlarmActiveted = false; // otherwise when next time door opened alarm will not activate
}
else // if alarm not activated no need to do anything
{
}
}
}