|
Treehopper C++ API
|
Represents a single LED that may or may not have _brightness control More...
#include <Led.h>
Public Member Functions | |
| Led (LedDriver &driver, int channel=0, bool hasBrightnessControl=false) | |
| Construct a new LED More... | |
| Led & | operator= (const Led &rhs) |
| void | brightness (double value) |
| Gets or sets the _brightness (0.0 - 1.0) of the LED (if it has _brightness control) More... | |
| double | brightness () |
| bool | state () |
| Gets or sets the _state of the LED More... | |
| void | state (bool value) |
Public Attributes | |
| const int | channel |
| Gets or sets the channel this LED belongs to More... | |
| const bool | hasBrightnessControl |
| Gets whether the LED has _brightness control More... | |
Friends | |
| std::ostream & | operator<< (std::ostream &stream, const Led &led) |
| Gets a string representation of the LED's current _state More... | |
The default state of a newly-constructed LED is "false" (off) with a brightness of 1.0 (even if this LED does not support _brightness control). This allows LEDs to be used with many non-dimmable display classes (such as SevenSegmentDigit, or BarGraph) that only control the LED _state. Note that for an LED to be on, its _state must be "true" and its _brightness must be non-zero.
Do not confuse the state's value with the electrical value on the pin; most LED drivers are open-drain, thus a "true" _state i.e., when the LED is on actually corresponds to the pin being driven to 0 (logic false); this is handled by the individual LED drivers to remove ambiguity. If your driver supports driving LEDs in either common-anode (open-drain) or common-cathode configurations, ensure the driver itself is configured to match your circuit.
You can also attach LEDs to pins that don't belong to LED drivers; see GpioLedDriver<TDigitalOutPin> and PwmLedDriver<TPwm>, which perform the necessary conversions.
| driver | The driver this LED is attached to |
| channel | The channel to use |
| hasBrightnessControl | Whether the LED has _brightness control |
| void brightness | ( | double | value | ) |
The _brightness is perceptual on a linear scale; i.e., a _brightness of 0.5 will be perceived as half as bright as a _brightness of 1.0.
Note that the LED will only illuminate if the state is true, regardless of the value of this property.
| double brightness | ( | ) |
| bool state | ( | ) |
Note that if the LED has _brightness control, it will only illuminate if the brightness of the LED is also non-zero.
| void state | ( | bool | value | ) |
|
friend |
| const int channel |
| const bool hasBrightnessControl |