ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
esp8266_pwm.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP8266
4
6#include "esphome/core/hal.h"
9
10namespace esphome::esp8266_pwm {
11
13 public:
14 void set_pin(InternalGPIOPin *pin) { pin_ = pin; }
17 void update_frequency(float frequency) override {
18 this->set_frequency(frequency);
19 this->write_state(this->last_output_);
20 }
21
23 void setup() override;
24 void dump_config() override;
26 float get_setup_priority() const override { return setup_priority::HARDWARE; }
27
28 protected:
29 void write_state(float state) override;
30
32 float frequency_{1000.0};
34 float last_output_{0.0};
35};
36
37template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
38 public:
41
42 void play(const Ts &...x) {
43 float freq = this->frequency_.value(x...);
44 this->parent_->update_frequency(freq);
45 }
46
48};
49
50} // namespace esphome::esp8266_pwm
51
52#endif
uint16_le_t frequency
Definition bl0942.h:6
void set_frequency(float frequency)
Definition esp8266_pwm.h:15
float get_setup_priority() const override
HARDWARE setup_priority.
Definition esp8266_pwm.h:26
void set_pin(InternalGPIOPin *pin)
Definition esp8266_pwm.h:14
void update_frequency(float frequency) override
Dynamically update frequency.
Definition esp8266_pwm.h:17
float last_output_
Cache last output level for dynamic frequency updating.
Definition esp8266_pwm.h:34
void write_state(float state) override
void setup() override
Initialize pin.
Base class for all output components that can output a variable level, like PWM.
bool state
Definition fan.h:2
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.h:41
uint16_t x
Definition tt21100.cpp:5