Arduino code

This commit is contained in:
Dejvino 2022-03-29 07:22:25 +02:00
parent 7b5ca987c0
commit c2c86520e0

71
code.ino Normal file
View File

@ -0,0 +1,71 @@
#define LOW_POWER_SLEEP
#define SLOW_START_DELAY 1000 // 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("...");
beep(100, 10);
delay(SLOW_START_DELAY);
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, 200);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
void loop() {
// nothing to do!
#ifdef LOW_POWER_SLEEP
Watchdog.sleep();
#else
delay(1000);
#endif
}