73 lines
1.3 KiB
C++
73 lines
1.3 KiB
C++
#define LOW_POWER_SLEEP // dependency: Adafruit SleepyDog
|
|
|
|
#define SLOW_START_DELAY 5000 // ms
|
|
#define PIN_SPEAKER 12
|
|
|
|
#define RELAYS 8
|
|
int relayPins[] = {
|
|
2, 3, 4, 5, 6, 7, 8, 9
|
|
};
|
|
|
|
#ifdef LOW_POWER_SLEEP
|
|
#include <Adafruit_SleepyDog.h>
|
|
#endif
|
|
|
|
void beep(int freq, int ms) {
|
|
tone(PIN_SPEAKER, freq, ms);
|
|
delay(ms);
|
|
}
|
|
|
|
void setup() {
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
for (int i = 0; i < RELAYS; i++) {
|
|
pinMode(relayPins[i], OUTPUT);
|
|
digitalWrite(relayPins[i], LOW);
|
|
}
|
|
|
|
Serial.begin(115200);
|
|
while (!Serial)
|
|
delay(10);
|
|
|
|
Serial.println();
|
|
Serial.println(" [ Slow-start Power Socket ] ");
|
|
|
|
beep(440, 200);
|
|
delay(1000);
|
|
|
|
for (int i = 0; i < RELAYS; i++) {
|
|
Serial.println("...");
|
|
delay(SLOW_START_DELAY/2);
|
|
beep(100, 10);
|
|
delay(SLOW_START_DELAY/2);
|
|
|
|
Serial.print("Starting ");
|
|
Serial.print(i+1);
|
|
Serial.print(" ... ");
|
|
|
|
beep(200, 50);
|
|
digitalWrite(relayPins[i], HIGH);
|
|
|
|
Serial.println("Done.");
|
|
beep(460, 100);
|
|
}
|
|
|
|
Serial.println();
|
|
Serial.println("Finished!");
|
|
delay(1000);
|
|
beep(210, 100);
|
|
beep(420, 100);
|
|
beep(560, 500);
|
|
digitalWrite(LED_BUILTIN, LOW);
|
|
delay(1000);
|
|
}
|
|
|
|
void loop() {
|
|
// nothing to do!
|
|
#ifdef LOW_POWER_SLEEP
|
|
Watchdog.sleep();
|
|
#else
|
|
delay(1000);
|
|
#endif
|
|
}
|