diff --git a/esphome/components/rp2040_pwm/rp2040_pwm.cpp b/esphome/components/rp2040_pwm/rp2040_pwm.cpp index 3f95125578..664a3734f7 100644 --- a/esphome/components/rp2040_pwm/rp2040_pwm.cpp +++ b/esphome/components/rp2040_pwm/rp2040_pwm.cpp @@ -42,9 +42,9 @@ void HOT RP2040PWM::write_state(float state) { state = 1.0f - state; } - if (frequency_changed_) { + if (this->frequency_changed_) { this->setup_pwm_(); - frequency_changed_ = false; + this->frequency_changed_ = false; } gpio_set_function(this->pin_->get_pin(), GPIO_FUNC_PWM); diff --git a/esphome/components/rp2040_pwm/rp2040_pwm.h b/esphome/components/rp2040_pwm/rp2040_pwm.h index 903079df17..9c88826ae9 100644 --- a/esphome/components/rp2040_pwm/rp2040_pwm.h +++ b/esphome/components/rp2040_pwm/rp2040_pwm.h @@ -10,8 +10,6 @@ namespace esphome { namespace rp2040_pwm { -static bool frequency_changed_ = false; - class RP2040PWM : public output::FloatOutput, public Component { public: void set_pin(InternalGPIOPin *pin) { pin_ = pin; } @@ -19,7 +17,7 @@ class RP2040PWM : public output::FloatOutput, public Component { /// Dynamically update frequency void update_frequency(float frequency) override { this->set_frequency(frequency); - frequency_changed_ = true; + this->frequency_changed_ = true; this->write_state(this->last_output_); } @@ -38,6 +36,7 @@ class RP2040PWM : public output::FloatOutput, public Component { float frequency_{1000.0}; /// Cache last output level for dynamic frequency updating float last_output_{0.0}; + bool frequency_changed_{false}; }; template class SetFrequencyAction : public Action {