unsigned long SleepStart = 0;
const unsigned long SleepInterval = 32400000UL;
void loop() {
switch (mode) {
case NORMAL:
analogWrite(ULNOutputPin, 255);
break;
case SLEEP:
analogWrite(ULNOutputPin,0);
if (millis() - SleepStart > SleepInterval)
mode = NORMAL; // Resume normal operation
#ifdef DEBUG
Serial.print("\nSleeping...");
#endif
break;
}
// Button "Sleep" pressed?
if (sleepButton.pressed()) {
if(mode == NORMAL) {
mode = SLEEP;
SleepStart = millis();
} else {
mode = NORMAL;
}
#ifdef DEBUG
Serial.print("\nSleep-Button pressed, mode is now ");
Serial.print(mode);
#endif
}
}