A little less work to activate/deactivate debugging serial output to the monitor -
// --- UNCOMMENT FOLLOWING TO ACTIVATE DEBUGGING CODE
//#define DEBUG_PRINT
#ifndef DEBUG_PRINT
#define DebugPrint(X)
#define DebugPrintln(X)
#else
#define DebugPrint(X) Serial.print(X)
#define DebugPrintln(X) Serial.println(X)
#endif
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
DebugPrint("\nSleeping...");
break;
}
// Button "Sleep" pressed?
if (sleepButton.pressed()) {
if(mode == NORMAL) {
mode = SLEEP;
SleepStart = millis();
} else {
mode = NORMAL;
}
DebugPrint("\nSleep-Button pressed, mode is now ");
DebugPrint(mode);
}
}