Treehopper C++ API
Led Class Reference

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...
 
Ledoperator= (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Led()

Led ( LedDriver driver,
int  channel = 0,
bool  hasBrightnessControl = false 
)
Parameters
driverThe driver this LED is attached to
channelThe channel to use
hasBrightnessControlWhether the LED has _brightness control

Member Function Documentation

◆ brightness() [1/2]

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.

◆ brightness() [2/2]

double brightness ( )

◆ operator=()

Led& operator= ( const Led rhs)
inline

◆ state() [1/2]

bool state ( )

Note that if the LED has _brightness control, it will only illuminate if the brightness of the LED is also non-zero.

◆ state() [2/2]

void state ( bool  value)

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
const Led led 
)
friend
Returns
A string representing the _state and _brightness of the LED

Member Data Documentation

◆ channel

const int channel

◆ hasBrightnessControl

const bool hasBrightnessControl

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