7RgbLed::RgbLed(
int led_r_pin,
int led_g_pin,
int led_b_pin, String config_path,
8 long int led_on_rgb,
long int led_off_rgb,
bool common_anode)
10 led_on_rgb_{led_on_rgb},
11 led_off_rgb_{led_off_rgb},
12 common_anode_{common_anode},
13 led_r_pin_{led_r_pin},
14 led_g_pin_{led_g_pin},
15 led_b_pin_{led_b_pin} {
18#if ESP_ARDUINO_VERSION_MAJOR > 2
7RgbLed::RgbLed(
int led_r_pin,
int led_g_pin,
int led_b_pin, String config_path, {
…}
29static float get_pwm(int64_t rgb,
int shift_right,
bool common_anode) {
30 int color_val = (rgb >> shift_right) & 0xFF;
31 float const color_pct = color_val / 255.0;
34 return 1.0 - color_pct;
46 String expected[] = {
"led_on_rgb",
"led_off_rgb"};
47 for (
auto str : expected) {
48 if (!config[str].is<JsonVariant>()) {
63#if ESP_ARDUINO_VERSION_MAJOR > 2
64 ledcWrite(
led_r_pin_,
static_cast<int>(r * max_brightness));
65 ledcWrite(
led_g_pin_,
static_cast<int>(g * max_brightness));
66 ledcWrite(
led_b_pin_,
static_cast<int>(b * max_brightness));
75 return R
"({"type":"object","properties":{"led_on_rgb":{"title":"RGB color for led ON","type":"integer"},"led_off_rgb":{"title":"RGB color for led OFF","type":"integer"}}})";
virtual bool load() override
Load and populate the object from a persistent storage.
virtual void set(const float &new_value) override
A special device object that can be used to control a multi-channel color rgb LED light using up to 3...
RgbLed(int led_r_pin=-1, int led_g_pin=-1, int led_b_pin=-1, String config_path="", long int led_on_rgb=0x00FF00, long int led_off_rgb=0xFF0000, bool common_anode=true)
void set_color(long new_value)
virtual bool from_json(const JsonObject &config) override
virtual bool to_json(JsonObject &root) override
const String ConfigSchema(const SmartSwitchController &obj)
constexpr int kPWMResolution