* Toggle relay with set on and off durations
* Power switch interrupt to toggle cycling of relay
const int powerSwitch = 2;
volatile bool isActive = false;
digitalWrite(relay, HIGH);
digitalWrite(bathLed, HIGH);
digitalWrite(relay, LOW);
digitalWrite(bathLed, LOW);
digitalWrite(powerLed, isActive);
// Delay with escape logic
void await(long timeToWait) {
for(int j=0; j<timeToWait; j++) {
if(isActive == LOW) return;
// Set both relay and powerLed pins to OUTPUT
pinMode(powerLed, OUTPUT);
// Set power switch pin to INPUT
pinMode(powerSwitch, INPUT);
// Default power switch to HIGH state
// Pressing switch brings it LOW
digitalWrite(powerSwitch, HIGH);
// Attach an interrupt to the power switch pin
attachInterrupt(digitalPinToInterrupt(powerSwitch), toggleState, FALLING);
// Turn on relay for on duration
// Turn off relay for off duration