SensESP 2.7.2
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 led_on_rgb=0x00FF00, long led_off_rgb=0xFF0000, bool common_anode=true)
 
virtual void set_input (long new_value, uint8_t input_channel=0) override
 
virtual void set_input (bool new_value, uint8_t input_channel=0) override
 
virtual void get_configuration (JsonObject &doc) override
 
virtual bool set_configuration (const JsonObject &config) override
 
virtual String get_config_schema () override
 
- Public Member Functions inherited from sensesp::Configurable
 Configurable (String config_path="", String description="", int sort_order=1000)
 
String get_description ()
 
void set_description (String description)
 Set the description of the Configurable.
 
int get_sort_order ()
 
void set_sort_order (int sort_order)
 
virtual void save_configuration ()
 
- Public Member Functions inherited from sensesp::ValueConsumer< long >
void connect_from (ValueProducer< long > *producer, uint8_t input_channel=0)
 
- Public Member Functions inherited from sensesp::ValueConsumer< bool >
void connect_from (ValueProducer< bool > *producer, uint8_t input_channel=0)
 

Protected Attributes

int led_r_channel_
 
int led_g_channel_
 
int led_b_channel_
 
long led_on_rgb_
 
long led_off_rgb_
 
bool common_anode_
 
- Protected Attributes inherited from sensesp::Configurable
String description_ = ""
 
int sort_order_ = 1000
 

Additional Inherited Members

- Public Attributes inherited from sensesp::Configurable
const String config_path_
 
- Protected Member Functions inherited from sensesp::Configurable
virtual void load_configuration ()
 

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_input(long), or by setting the on/off state via set_input(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 27 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  led_on_rgb = 0x00FF00,
long  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

◆ get_config_schema()

String sensesp::RgbLed::get_config_schema ( )
overridevirtual

Returns a configuration schema that specifies the key/value pairs that can be expected when calling get_configuration(), or are expected by set_configuration(). The schema will be in JSON Schema format

See also
https://json-schema.org

Reimplemented from sensesp::Configurable.

Definition at line 73 of file rgb_led.cpp.

◆ get_configuration()

void sensesp::RgbLed::get_configuration ( JsonObject configObject)
overridevirtual

Returns the current configuration data as a JsonObject. In general, the current state of local member variables are saved to a new object created with JsonDocument::as<JsonObject>() and returned.

Reimplemented from sensesp::Configurable.

Definition at line 60 of file rgb_led.cpp.

◆ set_configuration()

bool sensesp::RgbLed::set_configuration ( const JsonObject config)
overridevirtual

Sets the current state of local member variables using the data stored in config.

Reimplemented from sensesp::Configurable.

Definition at line 75 of file rgb_led.cpp.

◆ set_input() [1/2]

void sensesp::RgbLed::set_input ( bool  new_value,
uint8_t  input_channel = 0 
)
overridevirtual

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.

Reimplemented from sensesp::ValueConsumer< bool >.

Definition at line 52 of file rgb_led.cpp.

Here is the call graph for this function:

◆ set_input() [2/2]

void sensesp::RgbLed::set_input ( long  new_value,
uint8_t  input_channel = 0 
)
overridevirtual

Used to set the current display state of the LED.

Parameters
new_valueThe RGB color to display.

Reimplemented from sensesp::ValueConsumer< long >.

Definition at line 35 of file rgb_led.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ common_anode_

bool sensesp::RgbLed::common_anode_
protected

Definition at line 77 of file rgb_led.h.

◆ led_b_channel_

int sensesp::RgbLed::led_b_channel_
protected

Definition at line 74 of file rgb_led.h.

◆ led_g_channel_

int sensesp::RgbLed::led_g_channel_
protected

Definition at line 73 of file rgb_led.h.

◆ led_off_rgb_

long sensesp::RgbLed::led_off_rgb_
protected

Definition at line 76 of file rgb_led.h.

◆ led_on_rgb_

long sensesp::RgbLed::led_on_rgb_
protected

Definition at line 75 of file rgb_led.h.

◆ led_r_channel_

int sensesp::RgbLed::led_r_channel_
protected

Definition at line 72 of file rgb_led.h.


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