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_r_output_{std::make_shared<
PWMOutput>(led_r_pin)},
11 led_g_output_{std::make_shared<
PWMOutput>(led_g_pin)},
12 led_b_output_{std::make_shared<
PWMOutput>(led_b_pin)},
13 led_on_rgb_{led_on_rgb},
14 led_off_rgb_{led_off_rgb},
15 common_anode_{common_anode} {
23static float get_pwm(int64_t rgb,
int shift_right,
bool common_anode) {
24 int color_val = (rgb >> shift_right) & 0xFF;
25 float const color_pct = color_val / 255.0;
28 return 1.0 - color_pct;
40 String expected[] = {
"led_on_rgb",
"led_off_rgb"};
41 for (
auto str : expected) {
42 if (!config[str].is<JsonVariant>()) {
63 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.
Provides a cross platform mechanism for generating Pulse Width Modulation signals over one or more GP...
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)
std::shared_ptr< PWMOutput > led_g_output_
virtual bool from_json(const JsonObject &config) override
virtual bool to_json(JsonObject &root) override
std::shared_ptr< PWMOutput > led_b_output_
std::shared_ptr< PWMOutput > led_r_output_
const String ConfigSchema(const SmartSwitchController &obj)