RGB LED which can be set programatically to any of 16.7 million colours. More...
#include <sg_104030006_ChainableRGBLED.hpp>


Public Member Functions | |
| virtual | ~ChainableRGBLED (void) |
| Destructor. More... | |
| ChainableRGBLED (const size_t i=0, const std::string &n="", const bool turn_off_at_destruction=false) | |
| Constructor. More... | |
| ChainableRGBLED & | set_RGB (const RGB8 &colour) |
| Sets the LED to the specified colour, and updates the rgb internal colour value. More... | |
| ChainableRGBLED & | set_RGB (const double r, const double g, const double b) |
| Sets the LED to the specified colour, and updates the rgb internal colour value. More... | |
| ChainableRGBLED & | set_RGB (std::string html_colour) |
| Sets the LED to the specified colour, and updates the red, green, and blue internal variables. More... | |
| ChainableRGBLED & | turn_off (void) |
| Sets the LED to [0,0,0] effectively turning off the LED, but doesn't alter the rgb8 member of this class. More... | |
| ChainableRGBLED & | turn_on (void) |
| Sets the LED to the previously set value rgb8 defined above. More... | |
| ChainableRGBLED & | turn_on (const RGB8 &rgb, const bool reserved=true) |
| Set the LED to the specified colours, but doesn't alter the rgb8 variable defined above. More... | |
| ChainableRGBLED & | start_pulse_thread (const uint8_t r1=255, const uint8_t g1=255, const uint8_t b1=255, const uint8_t r2=0, const uint8_t g2=0, const uint8_t b2=0, const size_t length_of_pulse_in_milliseconds=1500) |
| Start a thread to pulse the LED between two sets of colours. More... | |
| ChainableRGBLED & | start_pulse_thread (const Colours8 &colours, size_t length_of_pulse_in_milliseconds=1500) |
| ChainableRGBLED & | stop_pulse_thread (void) |
| Stop any existing pulse thread. More... | |
| void | run_pulse_thread (uint8_t r1=255, uint8_t g1=255, uint8_t b1=255, uint8_t r2=0, uint8_t g2=0, uint8_t b2=0, size_t length_of_pulse_in_milliseconds=1500) |
| Runs a loop which causes the LED to pulse. More... | |
| void | run_pulse_thread (const Colours8 &colours, size_t length_of_pulse_in_milliseconds=1500) |
| virtual GroveGPIO & | send_2_bytes (uint16_t bits) |
| Send 16 bits (2 bytes). More... | |
| virtual GroveGPIO & | send_byte (uint8_t byte) |
| Send a single byte. More... | |
| virtual bool | is_grove_uart (void) const |
| Determine if this is a Grove UART device. More... | |
| virtual bool | is_grove_i2c (void) const |
| Determine if this is a Grove I2C device. More... | |
| virtual bool | is_grove_gpio (void) const |
| Determine if this is a Grove GPIO device. More... | |
| virtual uint32_t | get_sku (void) const |
| Return a guess as to the Seeed SKU number based on the grove type. More... | |
| virtual std::string | get_type_name (void) const |
| Return a short text string representing the grove type. More... | |
| virtual EGroveType | get_type (void) const |
| Return the grove type. More... | |
| virtual std::string | get_name (void) const |
| Return the user-supplied name. More... | |
| virtual std::string | get_description (void) const |
| Return a multi-word 1-line description of this object. More... | |
| bool | operator== (const GroveBase &rhs) const |
| Test object equality. More... | |
| bool | operator!= (const GroveBase &rhs) const |
| Test object equality. More... | |
Public Attributes | |
| size_t | idx |
| The index of the LED into the chain. More... | |
| RGB8 | rgb8 |
| 8-bit RGB colour. More... | |
| bool | turn_off_LED_when_destructing |
| Determines whether the destructor attempts to turn off the light. This can be specified in the constructor. More... | |
| EGroveType | grove_type |
| Grove type. More... | |
| std::string | grove_name |
| User-supplied name. More... | |
Protected Attributes | |
| std::thread | pulse_thread |
| std::atomic< bool > | pulse_thread_must_quit |
RGB LED which can be set programatically to any of 16.7 million colours.
Each component (red, green blue) can be set in intensity to any value between 0 and 255. Setting the colour to (0, 0, 0) will turn off the light, while (255, 255, 255) will result in bright white.
| Description | Image |
|---|---|
| Chainable RGB LED connected to the Grove UART interface. The light in this example was enabled from the command-line with "sudo seeedgrove chainable_rgb_led 255 128 0". |
|
GROVE cable connects to the 'in' side of the chainable RGB LED. |
|
|
virtual |
Destructor.
References SG::SGpp::get(), SG::SGpp::gpio, SG::GpioManagement::gpio_unexport(), stop_pulse_thread(), turn_off(), and turn_off_LED_when_destructing.

| SG::ChainableRGBLED::ChainableRGBLED | ( | const size_t | i = 0, |
| const std::string & | n = "", |
||
| const bool | turn_off_at_destruction = false |
||
| ) |
Constructor.
| [in] | i | Since the LEDs are chainable, i is the index of the LED into the chain. The first LED is idx zero. |
| [in] | n | User-supplied name which can be used to identify this LED. The name can be anything, it isn't parsed by SG++. |
| [in] | turn_off_at_destruction | Normally when an object of this class is destructed, the LED retains the very last state ("colour"). If turn_off_at_destruction is set to true, then the LED will be turned off by the destructor. |
References SG::SGpp::get(), SG::SGpp::gpio, SG::GpioManagement::gpio_export(), and SG::GpioManagement::kOutput.

|
virtualinherited |
Return a multi-word 1-line description of this object.
References SG::demangle(), SG::GroveBase::get_name(), SG::GroveBase::get_sku(), SG::GroveBase::get_type_name(), SG::GroveBase::is_grove_gpio(), SG::GroveBase::is_grove_i2c(), SG::GroveBase::is_grove_uart(), and SG::BeagleBone::Detect::to_string().
Referenced by buzzer(), chainable_rgb_led(), common_oled(), SG::GroveBase::get_name(), SG::GroveI2CDigital::GroveI2CDigital(), SG::CommonOLED::set_display_bitmap(), SG::CommonOLED::set_orientation(), temperature(), variable_led(), and SG::GroveI2CDigital::write_block().


|
inlinevirtualinherited |
Return the user-supplied name.
References SG::GroveBase::get_description(), SG::GroveBase::grove_name, SG::GroveBase::is_grove_gpio(), SG::GroveBase::is_grove_i2c(), and SG::GroveBase::is_grove_uart().
Referenced by SG::GroveBase::get_description(), SG::GroveBase::operator=(), and SG::GroveBase::operator==().


|
inlinevirtualinherited |
Return a guess as to the Seeed SKU number based on the grove type.
References SG::get_sku_from_grove_type(), and SG::GroveBase::grove_type.
Referenced by SG::GroveBase::get_description().


|
inlinevirtualinherited |
Return the grove type.
References SG::GroveBase::grove_type.
Referenced by SG::GroveI2CDigital::get_address_from_type(), SG::GroveBase::operator=(), and SG::GroveBase::operator==().

|
inlinevirtualinherited |
Return a short text string representing the grove type.
References SG::GroveBase::grove_type, and SG::to_string().
Referenced by SG::GroveBase::get_description().


|
inlinevirtualinherited |
|
inlinevirtualinherited |
|
inlinevirtualinherited |
|
inlineinherited |
Test object equality.
References SG::GroveBase::operator==().

|
inherited |
Test object equality.
References SG::GroveBase::get_name(), and SG::GroveBase::get_type().
Referenced by SG::GroveBase::operator!=(), SG::Buzzer::operator==(), SG::TemperatureAndHumiditySensor::operator==(), SG::TemperatureSensor::operator==(), and SG::I2CADC::operator==().


| void SG::ChainableRGBLED::run_pulse_thread | ( | uint8_t | r1 = 255, |
| uint8_t | g1 = 255, |
||
| uint8_t | b1 = 255, |
||
| uint8_t | r2 = 0, |
||
| uint8_t | g2 = 0, |
||
| uint8_t | b2 = 0, |
||
| size_t | length_of_pulse_in_milliseconds = 1500 |
||
| ) |
Runs a loop which causes the LED to pulse.
Normally, this is started on a secondary thread by start_pulse_thread(), though it can also be called directly. Call stop_pulse_thread() to force the loop to end.
References pulse_thread_must_quit, and turn_on().

| void SG::ChainableRGBLED::run_pulse_thread | ( | const Colours8 & | colours, |
| size_t | length_of_pulse_in_milliseconds = 1500 |
||
| ) |
|
virtualinherited |
Send 16 bits (2 bytes).
References SG::GroveGPIO::send_byte().

|
virtualinherited |
Send a single byte.
References SG::SGpp::get(), SG::SGpp::gpio, SG::GpioManagement::set_high(), and SG::GpioManagement::set_low().
Referenced by SG::GroveGPIO::send_2_bytes(), and turn_on().


| SG::ChainableRGBLED & SG::ChainableRGBLED::set_RGB | ( | const RGB8 & | colour | ) |
Sets the LED to the specified colour, and updates the rgb internal colour value.
References rgb8, and turn_on().
Referenced by chainable_rgb_led(), and set_RGB().


| SG::ChainableRGBLED & SG::ChainableRGBLED::set_RGB | ( | const double | r, |
| const double | g, | ||
| const double | b | ||
| ) |
Sets the LED to the specified colour, and updates the rgb internal colour value.
The range of r, g, and b is between 0.0 and 1.0 which is scaled up to a value between 0 and 255.
References set_RGB().

| SG::ChainableRGBLED & SG::ChainableRGBLED::set_RGB | ( | std::string | html_colour | ) |
Sets the LED to the specified colour, and updates the red, green, and blue internal variables.
| [in] | html_colour | The string must be formatted like an HTML colour entry, such as #00ff88 or #0f8. Colour names are not recognized. Values that cannot be parsed will be set to 0xff. |
References SG::RGB8::b, SG::RGB8::g, SG::RGB8::r, rgb8, and turn_on().

| SG::ChainableRGBLED & SG::ChainableRGBLED::start_pulse_thread | ( | const uint8_t | r1 = 255, |
| const uint8_t | g1 = 255, |
||
| const uint8_t | b1 = 255, |
||
| const uint8_t | r2 = 0, |
||
| const uint8_t | g2 = 0, |
||
| const uint8_t | b2 = 0, |
||
| const size_t | length_of_pulse_in_milliseconds = 1500 |
||
| ) |
Start a thread to pulse the LED between two sets of colours.
If a pulse thread is already running, it will be stopped before starting a new one. Calling any of the set_RGB(), turn_off(), or turn_on() will also automatically stop any running pulse threads. If this method is called multiple times, only the last colour values will be used.
References pulse_thread_must_quit, and stop_pulse_thread().
Referenced by chainable_rgb_led().


| ChainableRGBLED& SG::ChainableRGBLED::start_pulse_thread | ( | const Colours8 & | colours, |
| size_t | length_of_pulse_in_milliseconds = 1500 |
||
| ) |
| SG::ChainableRGBLED & SG::ChainableRGBLED::stop_pulse_thread | ( | void | ) |
Stop any existing pulse thread.
References pulse_thread, and pulse_thread_must_quit.
Referenced by start_pulse_thread(), turn_on(), and ~ChainableRGBLED().

| SG::ChainableRGBLED & SG::ChainableRGBLED::turn_off | ( | void | ) |
Sets the LED to [0,0,0] effectively turning off the LED, but doesn't alter the rgb8 member of this class.
This way, calling turn_on() will re-activate the LED to the previous preset colour.
References turn_on().
Referenced by ~ChainableRGBLED().


| SG::ChainableRGBLED & SG::ChainableRGBLED::turn_on | ( | void | ) |
Sets the LED to the previously set value rgb8 defined above.
References SG::RGB8::b, SG::RGB8::g, SG::RGB8::r, and rgb8.
Referenced by run_pulse_thread(), set_RGB(), and turn_off().

| SG::ChainableRGBLED & SG::ChainableRGBLED::turn_on | ( | const RGB8 & | rgb, |
| const bool | reserved = true |
||
| ) |
Set the LED to the specified colours, but doesn't alter the rgb8 variable defined above.
Normally you'd call set_RGB(), unless you want to temporarily change the LED colour without altering the original saved colour value.
| [in] | reserved | Used internally to determine if the pulse thread must be stopped. From an external API point of view, leave this parameter to true. |
References SG::RGB8::b, SG::RGB8::g, SG::RGB8::r, SG::GroveGPIO::send_byte(), and stop_pulse_thread().

|
inherited |
User-supplied name.
Referenced by SG::GroveBase::get_name(), and SG::GroveBase::operator=().
|
inherited |
Grove type.
Referenced by SG::GroveBase::get_sku(), SG::GroveBase::get_type(), SG::GroveBase::get_type_name(), and SG::GroveBase::operator=().
| size_t SG::ChainableRGBLED::idx |
The index of the LED into the chain.
The first LED is index zero. Normally, idx should be zero. Only set this if you have multiple chainable LEDs connected together.
|
protected |
Referenced by stop_pulse_thread().
|
protected |
Referenced by run_pulse_thread(), start_pulse_thread(), and stop_pulse_thread().
| RGB8 SG::ChainableRGBLED::rgb8 |
8-bit RGB colour.
This is an internal value stored in the C++ object, and may not be the same as the actual LED's intensity.
For example, see turn_off() which alters the colour of the LED, but does not change the rgb8 variable. This way, calling turn_on() will return the LED to the previous colour.
| bool SG::ChainableRGBLED::turn_off_LED_when_destructing |
Determines whether the destructor attempts to turn off the light. This can be specified in the constructor.
Referenced by ~ChainableRGBLED().