# define bathroomir 6
# define bathroomled 7
void setup() {
pinMode(bathroomir, INPUT_PULLUP);
pinMode(bathroomled, OUTPUT);
}
unsigned char ledState;
unsigned char buttonState;
unsigned long lastDebounceTime;
# define debounceDelay 25
void loop() {
if ((millis() - lastDebounceTime) > debounceDelay) {
int reading = !digitalRead(bathroomir); // 1 is pressed with INPUT_PULLUP wired to ground (! operator)
if (reading != buttonState) {
lastDebounceTime = millis();
buttonState = reading;
if (reading == HIGH) {
ledState = !ledState;
}
}
}
digitalWrite(bathroomled, ledState);
}
/*
//AUTO BATHROOM LIGHT ON OF
int reading = digitalRead(bathroomir);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
ledState = !ledState;
}
}
}
digitalWrite(bathroomled, ledState);
lastButtonState = reading;
*/