![]() |
RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
|
An RGB LED driven by three PWM pins (red, green, blue). More...
#include <RGBLED.h>
Public Member Functions | |
| RGBLED (const unsigned int redPinNumber, const unsigned int greenPinNumber, const unsigned int bluePinNumber) | |
| Builds an RGB LED on the three given PWM pins. More... | |
| virtual | ~RGBLED () |
| Destroys the LED, stopping soft PWM on all three pins. More... | |
| virtual void | TurnOn () override |
| Turns the LED on: (re)initializes PWM on all three pins and drives it white. More... | |
| virtual void | TurnOff () override |
| Turns the LED off: drives it black and stops soft PWM on all three pins. More... | |
| virtual void | ProcessRawValues () override |
| Processes the LED's raw values. More... | |
| virtual std::string | ToString () const override |
| Serializes the LED's three pin numbers to a string. More... | |
| void | TurnRed () |
| Drives the LED red. More... | |
| void | TurnGreen () |
| Drives the LED green. More... | |
| void | TurnBlue () |
| Drives the LED blue. More... | |
| void | TurnYellow () |
| Drives the LED yellow (red + green). More... | |
| void | TurnPurple () |
| Drives the LED purple (red + blue). More... | |
| void | TurnWhite () |
| Drives the LED white (all channels full). More... | |
| void | TurnBlack () |
| Drives the LED black (all channels off). More... | |
| void | TurnColor (const unsigned char redVal, const unsigned char greenVal, const unsigned char blueVal) |
| Sets all three channels' PWM levels at once (an arbitrary color). More... | |
| void | FadeFromRedToGreen () |
| Fades from red to green. More... | |
| void | FadeFromGreenToBlue () |
| Fades from green to blue. More... | |
| void | FadeFromBlueToYellow () |
| Fades from blue to yellow. More... | |
| void | FadeFromPurpleToRed () |
| Fades from purple to red. More... | |
| void | FadeToColor (const unsigned char startRedVal, const unsigned char startGreenVal, const unsigned char startBlueVal, const unsigned char endRedVal, const unsigned char endGreenVal, const unsigned char endBlueVal) |
| Smoothly fades all three 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 named colors and fades, pausing between each step. More... | |
| unsigned int | GetRedPinNumber () const |
| Gets the PWM pin for the red channel. More... | |
| unsigned int | GetGreenPinNumber () const |
| Gets the PWM pin for the green channel. More... | |
| unsigned int | GetBluePinNumber () const |
| Gets the PWM pin for the blue channel. 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 | myRedPinNumber |
| The PWM pin for the red channel. More... | |
| unsigned int | myGreenPinNumber |
| The PWM pin for the green channel. More... | |
| unsigned int | myBluePinNumber |
| The PWM pin for the blue channel. 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... | |
An RGB LED driven by three PWM pins (red, green, blue).
Supports named colors, arbitrary blends, and fading between colors.
| RumPi::RGBLED::RGBLED | ( | const unsigned int | redPinNumber, |
| const unsigned int | greenPinNumber, | ||
| const unsigned int | bluePinNumber | ||
| ) |
Builds an RGB LED on the three given PWM pins.
Soft PWM is created in TurnOn (not the constructor).
| [in] | redPinNumber | The PWM pin for the red channel. |
| [in] | greenPinNumber | The PWM pin for the green channel. |
| [in] | bluePinNumber | The PWM pin for the blue channel. |
|
virtual |
| void RumPi::RGBLED::FadeFromBlueToYellow | ( | ) |
Fades from blue to yellow.
| void RumPi::RGBLED::FadeFromGreenToBlue | ( | ) |
Fades from green to blue.
| void RumPi::RGBLED::FadeFromPurpleToRed | ( | ) |
Fades from purple to red.
| void RumPi::RGBLED::FadeFromRedToGreen | ( | ) |
Fades from red to green.
| void RumPi::RGBLED::FadeToColor | ( | const unsigned char | startRedVal, |
| const unsigned char | startGreenVal, | ||
| const unsigned char | startBlueVal, | ||
| const unsigned char | endRedVal, | ||
| const unsigned char | endGreenVal, | ||
| const unsigned char | endBlueVal | ||
| ) |
Smoothly fades all three channels from their start levels to their end levels, one PWM step at a time.
Blocks until the target color is reached.
| [in] | startRedVal | The red channel's starting PWM level. |
| [in] | startGreenVal | The green channel's starting PWM level. |
| [in] | startBlueVal | The blue channel's starting PWM level. |
| [in] | endRedVal | The red channel's target PWM level. |
| [in] | endGreenVal | The green channel's target PWM level. |
| [in] | endBlueVal | The blue channel's target PWM level. |
| unsigned int RumPi::RGBLED::GetBluePinNumber | ( | ) | const |
Gets the PWM pin for the blue channel.
| unsigned int RumPi::RGBLED::GetGreenPinNumber | ( | ) | const |
Gets the PWM pin for the green channel.
| unsigned int RumPi::RGBLED::GetRedPinNumber | ( | ) | const |
Gets the PWM pin for the red channel.
|
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::RGBLED::RunColorTest | ( | ) |
Runs a short demo that cycles through the named colors and fades, pausing between each step.
|
overridevirtual |
Serializes the LED's three pin numbers to a string.
Implements RumPi::BaseComponent.
| void RumPi::RGBLED::TurnBlack | ( | ) |
| void RumPi::RGBLED::TurnBlue | ( | ) |
| void RumPi::RGBLED::TurnColor | ( | const unsigned char | redVal, |
| const unsigned char | greenVal, | ||
| const unsigned char | blueVal | ||
| ) |
Sets all three channels' PWM levels at once (an arbitrary color).
| [in] | redVal | The red channel's PWM level (0-255). |
| [in] | greenVal | The green channel's PWM level (0-255). |
| [in] | blueVal | The blue channel's PWM level (0-255). |
| void RumPi::RGBLED::TurnGreen | ( | ) |
|
overridevirtual |
Turns the LED off: drives it black and stops soft PWM on all three pins.
Implements RumPi::BaseComponent.
|
overridevirtual |
Turns the LED on: (re)initializes PWM on all three pins and drives it white.
Implements RumPi::BaseComponent.
| void RumPi::RGBLED::TurnPurple | ( | ) |
| void RumPi::RGBLED::TurnRed | ( | ) |
| void RumPi::RGBLED::TurnWhite | ( | ) |
| void RumPi::RGBLED::TurnYellow | ( | ) |
|
private |
The PWM pin for the blue channel.
|
private |
The PWM pin for the green channel.
|
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 red channel.