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 int r, const int g, const int b) |
Sets the LED to the specified colour, and updates the red, green, and blue internal variables. More... | |
ChainableRGBLED & | set_RGB (const size_t r, const size_t g, const size_t b) |
Sets the LED to the specified colour, and updates the red, green, and blue internal variables. More... | |
ChainableRGBLED & | set_RGB (const double r, const double g, const double b) |
Sets the LED to the specified colour, and updates the red, green, and blue internal variables. 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 red, green, and blue members of this class. More... | |
ChainableRGBLED & | turn_on (void) |
Sets the LED to the previously set values red, green, and blue defined above. More... | |
ChainableRGBLED & | turn_on (const int r, const int g, const int b, const bool reserved=true) |
Set the LED to the specified colours, but doesn't alter the values red, green, or blue defined above. More... | |
ChainableRGBLED & | start_pulse_thread (const int r1=255, const int g1=255, const int b1=255, const int r2=0, const int g2=0, const int 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 & | stop_pulse_thread (void) |
Stop any existing pulse thread. More... | |
void | run_pulse_thread (int r1=255, int g1=255, int b1=255, int r2=0, int g2=0, int b2=0, size_t length_of_pulse_in_milliseconds=1500) |
Runs a loop which causes the LED to pulse. More... | |
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... | |
int | red |
Red component. Must be in the range 0-255. This is the internal value for red stored in the C++ object, and may not be the same as the actual LED's red intensity. More... | |
int | green |
Green component. Must be in the range 0-255. This is the internal value for green stored in the C++ object, and may not be the same as the actual LED's green intensity. More... | |
int | blue |
Blue component. Must be in the range 0-255. This is the internal value for blue stored in the C++ object, and may not be the same as the actual LED's blue intensity. 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::GroveI2CDigital::read16(), SG::GroveI2CDigital::read8(), SG::GroveI2CDigital::read_block(), SG::CommonOLED::set_display_bitmap(), SG::CommonOLED::set_orientation(), temperature(), variable_led(), SG::GroveI2CDigital::write16(), SG::GroveI2CDigital::write8(), SG::GroveI2CDigital::write_block(), and SG::GroveI2CDigital::write_byte().
|
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 | ( | int | r1 = 255 , |
int | g1 = 255 , |
||
int | b1 = 255 , |
||
int | r2 = 0 , |
||
int | g2 = 0 , |
||
int | 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().
Referenced by start_pulse_thread().
|
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 int | r, |
const int | g, | ||
const int | b | ||
) |
Sets the LED to the specified colour, and updates the red, green, and blue internal variables.
The range of r
, g
, and b
is 0 to 255. Values outside that range will automatically be brought within range.
References blue, green, red, and turn_on().
Referenced by chainable_rgb_led().
SG::ChainableRGBLED & SG::ChainableRGBLED::set_RGB | ( | const size_t | r, |
const size_t | g, | ||
const size_t | b | ||
) |
SG::ChainableRGBLED & SG::ChainableRGBLED::set_RGB | ( | const double | r, |
const double | g, | ||
const double | b | ||
) |
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 blue, green, red, and turn_on().
SG::ChainableRGBLED & SG::ChainableRGBLED::start_pulse_thread | ( | const int | r1 = 255 , |
const int | g1 = 255 , |
||
const int | b1 = 255 , |
||
const int | r2 = 0 , |
||
const int | g2 = 0 , |
||
const int | 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, pulse_thread_must_quit, run_pulse_thread(), and stop_pulse_thread().
Referenced by chainable_rgb_led().
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 red, green, and blue members 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 values red, green, and blue defined above.
References blue, green, and red.
Referenced by run_pulse_thread(), set_RGB(), and turn_off().
SG::ChainableRGBLED & SG::ChainableRGBLED::turn_on | ( | const int | r, |
const int | g, | ||
const int | b, | ||
const bool | reserved = true |
||
) |
Set the LED to the specified colours, but doesn't alter the values red, green, or blue defined above.
Normally you'd call set_RGB(), unless you want to temporarily change the LED colour without altering the original saved colour values.
[in] | r | Red component. Values below zero will be interpreted as zero. Values above 255 will be interpreted as 255. |
[in] | g | Green component. Values below zero will be interpreted as zero. Values above 255 will be interpreted as 255. |
[in] | b | Blue component. Values below zero will be interpreted as zero. Values above 255 will be interpreted as 255. |
[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 blue, green, red, SG::GroveGPIO::send_byte(), and stop_pulse_thread().
int SG::ChainableRGBLED::blue |
int SG::ChainableRGBLED::green |
|
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 start_pulse_thread(), and stop_pulse_thread().
|
protected |
Referenced by run_pulse_thread(), start_pulse_thread(), and stop_pulse_thread().
int SG::ChainableRGBLED::red |
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().