Add function (pulse) to second LED (Amica only)

This commit is contained in:
gilex-dev 2024-06-26 22:11:05 +02:00
parent 8f37203b79
commit ecdce86bb1
Signed by: gilex-dev
GPG Key ID: FBACA726925AFBEB
1 changed files with 22 additions and 1 deletions

View File

@ -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();
}