From f7db9aaa9f09a4c02fb1b942734f1881ab2f458c Mon Sep 17 00:00:00 2001 From: marshn Date: Thu, 30 Jun 2022 10:28:19 +0100 Subject: [PATCH] Fix slow_pwm output glitch (#3601) --- esphome/components/slow_pwm/slow_pwm_output.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/slow_pwm/slow_pwm_output.cpp b/esphome/components/slow_pwm/slow_pwm_output.cpp index 9cfeb54153..6af0283483 100644 --- a/esphome/components/slow_pwm/slow_pwm_output.cpp +++ b/esphome/components/slow_pwm/slow_pwm_output.cpp @@ -42,12 +42,12 @@ void SlowPWMOutput::loop() { uint32_t now = millis(); float scaled_state = this->state_ * this->period_; - if (now >= this->period_start_time_ + this->period_) { + if (now - this->period_start_time_ >= this->period_) { ESP_LOGVV(TAG, "End of period. State: %f, Scaled state: %f", this->state_, scaled_state); this->period_start_time_ += this->period_; } - this->set_output_state_(now < this->period_start_time_ + scaled_state); + this->set_output_state_(scaled_state > now - this->period_start_time_); } void SlowPWMOutput::dump_config() {