// This circuit switches an exhast fan (led) on for the time set by the three switches after
// the button has been pressed. Typical delay of 5, 10, 20 minutes making max time of 35 minutes.
// Relay NC contact used because my relay is faulty and NO does not work!
// variables:
int switch0 = 0; //switch 0 connected to digital pin 0
int switch1 = 1; //switch 1 connected to digital pin 1
int switch2 = 2; //switch 2 connected to digital pin 2
int pbStart3 = 3; //start push button connected to digital pin 3
int relayPin = 4; //relay connected to digital pin 4
int rstButton = 5; // restart button
int lsw0 = 0; //set initial value of switch0
int msw1 = 0; //set initial value of switch1
int hsw2 = 0; //set initial value of switch2
// int pbStart3 = HIGH; //set initial value of pbStart button
int totalDelay = 0; //sum of switch values
int subroutine1();
void setup() {
// put your setup code here, to run once:
pinMode(switch0, INPUT_PULLUP);
pinMode(switch1, INPUT_PULLUP);
pinMode(switch2, INPUT_PULLUP);
pinMode(pbStart3, INPUT_PULLUP);
pinMode(relayPin, OUTPUT);
pinMode(rstButton, INPUT_PULLUP);
digitalWrite(relayPin, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
int pbStart3Val = digitalRead(pbStart3);
if (pbStart3Val == HIGH) {
delay(150);
} else {
subroutine1();
}
}
int subroutine1() {
int sw0Val = digitalRead(switch0);
//sw0Val = LOW;
if (sw0Val == HIGH) {
lsw0 = 1;
} else {
lsw0 = 0;
}
int sw1Val = digitalRead(switch1);
//sw1Val = LOW;
if (sw1Val == HIGH) {
msw1 = 2;
} else {
msw1 = 0;
}
int sw2Val = digitalRead(switch2);
//sw2Val = LOW;
if (sw2Val == HIGH) {
hsw2 = 4;
} else {
hsw2 = 0;
}
totalDelay = (lsw0 + msw1 + hsw2) * 1000;
digitalWrite(relayPin, LOW);
delay(totalDelay);
digitalWrite(relayPin, HIGH);
delay(1000);
}