From ecdce86bb116aa3e23257c813eea2af76ff27b81 Mon Sep 17 00:00:00 2001 From: gilex-dev Date: Wed, 26 Jun 2024 22:11:05 +0200 Subject: [PATCH] Add function (pulse) to second LED (Amica only) --- src/main.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index fb9543c..56942ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -302,7 +302,7 @@ void timer() { sprintf(t_stat[r], "off"); if (!override[r]) { digitalWrite(pins[r], LOW); - analogWrite(LED_BUILTIN, 0); // LED + analogWrite(LED_BUILTIN_AUX, 0); // LED if (strcmp(stat[r], "AN") == 0) { debug(r); debugln(F(" is off")); @@ -314,6 +314,19 @@ void timer() { } } +uint ledBrightness = 0; +int ledBrightnessStep = 20; +uint lastLedCycle; +void pulseLed() { + if (millis() - lastLedCycle > 100) { + analogWrite(LED_BUILTIN_AUX, ledBrightness); + ledBrightness += ledBrightnessStep; + if (ledBrightness <= 0 || ledBrightness >= 255) { + ledBrightnessStep = -ledBrightnessStep; + } + lastLedCycle = millis(); + } +} void emergencyStop() { for (uint pin = 0; pin < sizeof(pins) / sizeof(pins[0]); pin++) { @@ -328,10 +341,13 @@ void emergencyStop() { unsigned long lastTry = millis(); while (millis() - lastTry < (1000 * 60)) { analogWrite(LED_BUILTIN, 255); + analogWrite(LED_BUILTIN_AUX, 0); delay(125); analogWrite(LED_BUILTIN, 0); + analogWrite(LED_BUILTIN_AUX, 255); delay(125); analogWrite(LED_BUILTIN, 255); + analogWrite(LED_BUILTIN_AUX, 255); delay(250); } ESP.restart(); @@ -350,7 +366,9 @@ void getCurrentTemperature() { void setup() { pinMode(LED_BUILTIN, OUTPUT); + pinMode(LED_BUILTIN_AUX, OUTPUT); analogWrite(LED_BUILTIN, 255); + analogWrite(LED_BUILTIN_AUX, 255); uint p = 0; while (p <= sizeof(pins) / sizeof(pins[0])) { pinMode(pins[p], OUTPUT); @@ -379,6 +397,7 @@ void setup() { while (WiFi.status() != WL_CONNECTED) { delay(250); debug(F(".")); + analogWrite(LED_BUILTIN_AUX, 255 * (notConnectedCounter % 2)); // LED notConnectedCounter++; if (notConnectedCounter > (1000 / 250) * 15) { // Reset board if not connected after 15s @@ -386,6 +405,7 @@ void setup() { ESP.restart(); } } + analogWrite(LED_BUILTIN_AUX, 0); debug(F("\nConnected to ")); debugln(WiFi.SSID()); debug(F("IP address: ")); @@ -431,4 +451,5 @@ void loop() { delay(50); events(); ArduinoOTA.handle(); + pulseLed(); }