SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::RgbLed Class Reference

A special device object that can be used to control a multi-channel color rgb LED light using up to 3 digital output channels. A "color" is defined using the standard 24 bit color depth numbers composed of three 8 bit channels for Red, Green, and Blue (see https://techterms.com/definition/rgb) More...

#include <sensesp/system/rgb_led.h>

Inheritance diagram for sensesp::RgbLed:
[legend]

Public Member Functions

 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)
 
virtual bool to_json (JsonObject &root) override
 
virtual bool from_json (const JsonObject &config) override
 
- Public Member Functions inherited from sensesp::FileSystemSaveable
 FileSystemSaveable (const String &config_path)
 
virtual bool load () override
 Load and populate the object from a persistent storage.
 
virtual bool save () override
 Save the object to a persistent storage.
 
virtual bool clear () override
 Delete the data from a persistent storage.
 
bool find_config_file (const String &config_path, String &filename)
 
- Public Member Functions inherited from sensesp::Saveable
 Saveable (const String &config_path)
 
virtual bool refresh ()
 Refresh the object. This may or may not access the persistent storage but is not expected to overwrite the object's state.
 
const String & get_config_path () const
 
- Public Member Functions inherited from sensesp::Serializable

Public Attributes

LambdaConsumer< long > rgb_consumer_
 
LambdaConsumer< bool > on_off_consumer_
 

Protected Member Functions

void set_color (long new_value)
 

Protected Attributes

std::shared_ptr< PWMOutputled_r_output_ = nullptr
 
std::shared_ptr< PWMOutputled_g_output_ = nullptr
 
std::shared_ptr< PWMOutputled_b_output_ = nullptr
 
long led_on_rgb_
 
long led_off_rgb_
 
bool common_anode_
 
- Protected Attributes inherited from sensesp::Saveable
const String config_path_
 

Detailed Description

A special device object that can be used to control a multi-channel color rgb LED light using up to 3 digital output channels. A "color" is defined using the standard 24 bit color depth numbers composed of three 8 bit channels for Red, Green, and Blue (see https://techterms.com/definition/rgb)

Color LEDs can be controlled by either setting the specific color to be displayed via the set(long), or by setting the on/off state via set(bool). When specifying a simple on/off via the the bool input, the default ON or OFF colors specified in the constructor are used.

You do not have to define all three channels (for example, if you are short on output pins, or if you happen to be using a two channel color led). Specify -1 for any pin for that channel to be ignored. The color values used still have to adhere to the 24 bit color definition however.

See also
PWMOutput

Definition at line 29 of file rgb_led.h.

Constructor & Destructor Documentation

◆ RgbLed()

sensesp::RgbLed::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 )

The constructor

Parameters
led_r_pinthe digital output pin that controls the red element of an RGB LED. Specify -1 if there is no red channel connected.
led_g_pinthe digital output pin that controls the green element of an RGB LED. Specify -1 if there is no green channel connected.
led_b_pinthe digital output pin that controls the blue element of an RGB LED. Specify -1 if there is no blue channel connected.
config_pathThe configuration path to use to load and save the user configurable values of this device. Use BLANK if this device can not have user configurable values.
led_on_rgbThe RGB color to use when the switch is in the "on" state. The default value is 0x00FF00, which is RGB for "green"
led_off_rgbThe RGB color to use when the switch is in the "off" state. The default value is 0xFF0000, which is RGB red
common_anodeTRUE if the led being used is a common_anode version (which inverts the PWM signal to obtain the necessary color). FALSE if the led is a common cathode

Definition at line 7 of file rgb_led.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ from_json()

bool sensesp::RgbLed::from_json ( const JsonObject & root)
overridevirtual

Deserializes the current object data from a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 39 of file rgb_led.cpp.

◆ set_color()

void sensesp::RgbLed::set_color ( long new_value)
protected

Definition at line 51 of file rgb_led.cpp.

◆ to_json()

bool sensesp::RgbLed::to_json ( JsonObject & root)
overridevirtual

Serializes the current object data into a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 33 of file rgb_led.cpp.

Member Data Documentation

◆ common_anode_

bool sensesp::RgbLed::common_anode_
protected

Definition at line 85 of file rgb_led.h.

◆ led_b_output_

std::shared_ptr<PWMOutput> sensesp::RgbLed::led_b_output_ = nullptr
protected

Definition at line 82 of file rgb_led.h.

◆ led_g_output_

std::shared_ptr<PWMOutput> sensesp::RgbLed::led_g_output_ = nullptr
protected

Definition at line 81 of file rgb_led.h.

◆ led_off_rgb_

long sensesp::RgbLed::led_off_rgb_
protected

Definition at line 84 of file rgb_led.h.

◆ led_on_rgb_

long sensesp::RgbLed::led_on_rgb_
protected

Definition at line 83 of file rgb_led.h.

◆ led_r_output_

std::shared_ptr<PWMOutput> sensesp::RgbLed::led_r_output_ = nullptr
protected

Definition at line 80 of file rgb_led.h.

◆ on_off_consumer_

LambdaConsumer<bool> sensesp::RgbLed::on_off_consumer_
Initial value:
=
LambdaConsumer<bool>([this](bool new_value) {
if (new_value) {
} else {
}
})
long led_off_rgb_
Definition rgb_led.h:84
long led_on_rgb_
Definition rgb_led.h:83
void set_color(long new_value)
Definition rgb_led.cpp:51

Used to set the current display state of the LED with a simple on/off boolean value. Using TRUE for new_value sets the color to the ON color. Using FALSE uses the OFF color.

Definition at line 67 of file rgb_led.h.

◆ rgb_consumer_

LambdaConsumer<long> sensesp::RgbLed::rgb_consumer_
Initial value:
=
LambdaConsumer<long>([this](long new_value) { set_color(new_value); })

Used to set the current display state of the LED.

Parameters
new_valueThe RGB color to display.

Definition at line 59 of file rgb_led.h.


The documentation for this class was generated from the following files: