diff --git a/analog_system_monitor_arduino/analog_system_monitor_arduino.ino b/analog_system_monitor_arduino/analog_system_monitor_arduino.ino index 6dee976..1cea4f3 100644 --- a/analog_system_monitor_arduino/analog_system_monitor_arduino.ino +++ b/analog_system_monitor_arduino/analog_system_monitor_arduino.ino @@ -183,19 +183,22 @@ void loop() { } } - // -------- Slew-rate limiting (smooth 1-second transitions) -------- - unsigned long now = millis(); - float progress = (float)(now - slewStartTime) / (float)slewDuration; - if (progress > 1.0f) progress = 1.0f; + // -------- Slew-rate limiting (only when NOT in watchdog mode) -------- + if (millis() - lastPacketTime <= watchdogTimeout) { - for (int ch = 0; ch < NUM_CHANNELS; ch++) { - float newDuty = slewStartDuty[ch] + (targetDuty[ch] - slewStartDuty[ch]) * progress; - currentDuty[ch] = newDuty; + unsigned long now = millis(); + float progress = (float)(now - slewStartTime) / (float)slewDuration; + if (progress > 1.0f) progress = 1.0f; - float calibratedDuty = applyCalibration(ch, newDuty); - int duty = (int)((calibratedDuty / 100.0f) * ((1 << pwmResolution) - 1)); + for (int ch = 0; ch < NUM_CHANNELS; ch++) { + float newDuty = slewStartDuty[ch] + (targetDuty[ch] - slewStartDuty[ch]) * progress; + currentDuty[ch] = newDuty; - ledcWrite(pwmPins[ch], duty); + float calibratedDuty = applyCalibration(ch, newDuty); + int duty = (int)((calibratedDuty / 100.0f) * ((1 << pwmResolution) - 1)); + + ledcWrite(pwmPins[ch], duty); + } } // -------- Watchdog fade-to-zero (UDP-based) --------