|
@ -0,0 +1,60 @@ |
|
|
|
|
|
int disable = 0; |
|
|
|
|
|
int timer = 0; |
|
|
|
|
|
int timerMAX = 900; //(countdown in seconds)
|
|
|
|
|
|
int fan = 0; |
|
|
|
|
|
int relayPin = 0; |
|
|
|
|
|
int fanPin = 1; |
|
|
|
|
|
|
|
|
|
|
|
void setup() { |
|
|
|
|
|
// put your setup code here, to run once:
|
|
|
|
|
|
pinMode(relayPin, OUTPUT); |
|
|
|
|
|
pinMode(fanPin, OUTPUT); |
|
|
|
|
|
digitalWrite(relayPin, LOW); |
|
|
|
|
|
digitalWrite(fanPin, LOW); |
|
|
|
|
|
timer = timerMAX; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void loop() { |
|
|
|
|
|
// put your main code here, to run repeatedly:
|
|
|
|
|
|
|
|
|
|
|
|
// only enable fans after the compressor has been running for a while
|
|
|
|
|
|
if (timer < (timerMAX*4/5) && disable == 0) { |
|
|
|
|
|
digitalWrite(fanPin, HIGH); |
|
|
|
|
|
} |
|
|
|
|
|
else if (timer == timerMAX) { |
|
|
|
|
|
digitalWrite(fanPin, LOW); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// compressor control logic
|
|
|
|
|
|
if (timer > 0 && disable == 0) { |
|
|
|
|
|
// when compressor is active, countdown moves at 1s/cycle
|
|
|
|
|
|
timer--; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else if (timer > 0 && disable == 1) { |
|
|
|
|
|
// when compressor is off, countdown moves at 5s/cycle
|
|
|
|
|
|
timer = timer - 5; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else if (timer == 0) { |
|
|
|
|
|
// reset countdown timer to max once 0 is reached
|
|
|
|
|
|
timer = timerMAX; |
|
|
|
|
|
|
|
|
|
|
|
// realy control logic: warning! LOW = active!
|
|
|
|
|
|
if (disable == 0) { |
|
|
|
|
|
disable = 1; |
|
|
|
|
|
digitalWrite(relayPin, HIGH); |
|
|
|
|
|
} |
|
|
|
|
|
else if (disable == 1) { |
|
|
|
|
|
disable = 0; |
|
|
|
|
|
digitalWrite(relayPin, LOW); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else { //protect against underflow or bitflip
|
|
|
|
|
|
timer = 0; |
|
|
|
|
|
disable = 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
delay(1000); |
|
|
|
|
|
} |