![]() |
RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
|
A bi-color LED driven by two PWM pins (one per color). More...
#include <DualLED.h>
Public Member Functions | |
| DualLED (const unsigned int firstColorPinNumber, const unsigned int secondColorPinNumber) | |
| Builds a dual-color LED on the two given PWM pins. More... | |
| virtual | ~DualLED () |
| Destroys the LED, stopping soft PWM on both pins. More... | |
| virtual void | TurnOn () override |
| Turns the LED on: (re)initializes PWM on both pins and drives both colors to full. More... | |
| virtual void | TurnOff () override |
| Turns the LED off: drives both colors to zero and stops soft PWM so the LED is actually off. More... | |
| virtual void | ProcessRawValues () override |
| Processes the LED's raw values. More... | |
| virtual std::string | ToString () const override |
| Serializes the LED's two pin numbers to a string. More... | |
| void | TurnOnFirstColor () |
| Drives the first color fully on. More... | |
| void | TurnOnSecondColor () |
| Drives the second color fully on. More... | |
| void | TurnOffFirstColor () |
| Drives the first color off. More... | |
| void | TurnOffSecondColor () |
| Drives the second color off. More... | |
| void | TurnFirstColor (const unsigned char firstColorVal) |
| Sets the first color's PWM level. More... | |
| void | TurnSecondColor (const unsigned char secondColorVal) |
| Sets the second color's PWM level. More... | |
| void | TurnColor (const unsigned char firstColorVal, const unsigned char secondColorVal) |
| Sets both colors' PWM levels at once (a blended color). More... | |
| void | FadeFromFirstToSecondColor () |
| Fades from the first color fully on to the second color fully on. More... | |
| void | FadeFromSecondColorToFirstColor () |
| Fades from the second color fully on to the first color fully on. More... | |
| void | FadeToColor (const unsigned char startFirstColorVal, const unsigned char startSecondColorVal, const unsigned char endFirstColorVal, const unsigned char endSecondColorVal) |
| Smoothly fades both channels from their start levels to their end levels, one PWM step at a time. More... | |
| void | RunColorTest () |
| Runs a short demo that cycles through the LED's on/off and fade behaviours, pausing between each step. More... | |
| unsigned int | GetFirstColorPinNumber () const |
| Gets the PWM pin for the first color. More... | |
| unsigned int | GetSecondColorPinNumber () const |
| Gets the PWM pin for the second color. More... | |
Public Member Functions inherited from RumPi::BaseComponent | |
| BaseComponent () | |
| Builds a base component with an unknown type and an empty name. More... | |
| virtual | ~BaseComponent () |
| Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More... | |
| virtual void | TurnOn ()=0 |
| Turns the component on (e.g. More... | |
| virtual void | TurnOff ()=0 |
| Turns the component off. More... | |
| virtual std::string | ToString () const =0 |
| Serializes the component's current readings to a string (usually JSON). More... | |
| virtual void | ProcessRawValues ()=0 |
| Reads and processes the component's latest raw values (called once per poll). More... | |
| virtual EComponentType | GetComponentType () const |
| Gets the component's type. More... | |
| const std::string & | GetName () const |
| Gets the component's unique per-instance name. More... | |
| void | SetName (const std::string &name) |
| Sets the component's unique per-instance name. More... | |
Private Attributes | |
| unsigned int | myFirstColorPinNumber |
| The PWM pin for the first color. More... | |
| unsigned int | mySecondColorPinNumber |
| The PWM pin for the second color. More... | |
| bool | myIsOn |
| True while the PWM pins are created/on, so TurnOn/TurnOff are idempotent (a repeat call is a no-op). More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from RumPi::BaseComponent | |
| static std::string | ComponentTypeToString (const EComponentType theComponentTypeToConvert) |
| Maps an EComponentType to its string name. More... | |
| static EComponentType | StringToComponentType (const std::string &theComponentTypeName) |
| Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More... | |
Protected Attributes inherited from RumPi::BaseComponent | |
| EComponentType | myComponentType |
| The kind of component this is (set by each concrete subclass). More... | |
| std::string | myName |
| A unique per-instance name, assigned when the component is added to the manager. More... | |
A bi-color LED driven by two PWM pins (one per color).
Supports turning each color on or off, setting a blended level, and fading between the two colors.
| RumPi::DualLED::DualLED | ( | const unsigned int | firstColorPinNumber, |
| const unsigned int | secondColorPinNumber | ||
| ) |
Builds a dual-color LED on the two given PWM pins.
Soft PWM is created in TurnOn (not the constructor).
| [in] | firstColorPinNumber | The PWM pin for the first color. |
| [in] | secondColorPinNumber | The PWM pin for the second color. |
|
virtual |
| void RumPi::DualLED::FadeFromFirstToSecondColor | ( | ) |
Fades from the first color fully on to the second color fully on.
| void RumPi::DualLED::FadeFromSecondColorToFirstColor | ( | ) |
Fades from the second color fully on to the first color fully on.
| void RumPi::DualLED::FadeToColor | ( | const unsigned char | startFirstColorVal, |
| const unsigned char | startSecondColorVal, | ||
| const unsigned char | endFirstColorVal, | ||
| const unsigned char | endSecondColorVal | ||
| ) |
Smoothly fades both channels from their start levels to their end levels, one PWM step at a time.
Blocks until the target is reached.
| [in] | startFirstColorVal | The first color's starting PWM level. |
| [in] | startSecondColorVal | The second color's starting PWM level. |
| [in] | endFirstColorVal | The first color's target PWM level. |
| [in] | endSecondColorVal | The second color's target PWM level. |
| unsigned int RumPi::DualLED::GetFirstColorPinNumber | ( | ) | const |
Gets the PWM pin for the first color.
| unsigned int RumPi::DualLED::GetSecondColorPinNumber | ( | ) | const |
Gets the PWM pin for the second color.
|
overridevirtual |
Processes the LED's raw values.
Output-only, so there is nothing to read each cycle - this is a no-op.
Implements RumPi::BaseComponent.
| void RumPi::DualLED::RunColorTest | ( | ) |
Runs a short demo that cycles through the LED's on/off and fade behaviours, pausing between each step.
|
overridevirtual |
Serializes the LED's two pin numbers to a string.
Implements RumPi::BaseComponent.
| void RumPi::DualLED::TurnColor | ( | const unsigned char | firstColorVal, |
| const unsigned char | secondColorVal | ||
| ) |
Sets both colors' PWM levels at once (a blended color).
| [in] | firstColorVal | The first color's PWM level (0-255). |
| [in] | secondColorVal | The second color's PWM level (0-255). |
| void RumPi::DualLED::TurnFirstColor | ( | const unsigned char | firstColorVal | ) |
Sets the first color's PWM level.
| [in] | firstColorVal | The first color's PWM level (0-255). |
|
overridevirtual |
Turns the LED off: drives both colors to zero and stops soft PWM so the LED is actually off.
Implements RumPi::BaseComponent.
| void RumPi::DualLED::TurnOffFirstColor | ( | ) |
Drives the first color off.
| void RumPi::DualLED::TurnOffSecondColor | ( | ) |
Drives the second color off.
|
overridevirtual |
Turns the LED on: (re)initializes PWM on both pins and drives both colors to full.
Implements RumPi::BaseComponent.
| void RumPi::DualLED::TurnOnFirstColor | ( | ) |
Drives the first color fully on.
| void RumPi::DualLED::TurnOnSecondColor | ( | ) |
Drives the second color fully on.
| void RumPi::DualLED::TurnSecondColor | ( | const unsigned char | secondColorVal | ) |
Sets the second color's PWM level.
| [in] | secondColorVal | The second color's PWM level (0-255). |
|
private |
The PWM pin for the first color.
|
private |
True while the PWM pins are created/on, so TurnOn/TurnOff are idempotent (a repeat call is a no-op).
|
private |
The PWM pin for the second color.