RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::DualLED Class Reference

A bi-color LED driven by two PWM pins (one per color). More...

#include <DualLED.h>

Inheritance diagram for RumPi::DualLED:
[legend]
Collaboration diagram for RumPi::DualLED:
[legend]

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...
 

Detailed Description

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.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ DualLED()

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).

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnOn();
DualLED(const unsigned int firstColorPinNumber, const unsigned int secondColorPinNumber)
Builds a dual-color LED on the two given PWM pins.
Definition: DualLED.cpp:20
constexpr unsigned int PIN_GPIO_6
BCM GPIO pin 6.
Definition: Common.h:37
constexpr unsigned int PIN_GPIO_5
BCM GPIO pin 5.
Definition: Common.h:36
Parameters
[in]firstColorPinNumberThe PWM pin for the first color.
[in]secondColorPinNumberThe PWM pin for the second color.

◆ ~DualLED()

RumPi::DualLED::~DualLED ( )
virtual

Destroys the LED, stopping soft PWM on both pins.

Author
Eddie O'Hagan
Date
8/13/2026
DualLED* led = new DualLED(5, 6);
delete led;

Member Function Documentation

◆ FadeFromFirstToSecondColor()

void RumPi::DualLED::FadeFromFirstToSecondColor ( )

Fades from the first color fully on to the second color fully on.

Author
Eddie O'Hagan
Date
8/13/2026
led.FadeFromFirstToSecondColor();

◆ FadeFromSecondColorToFirstColor()

void RumPi::DualLED::FadeFromSecondColorToFirstColor ( )

Fades from the second color fully on to the first color fully on.

Author
Eddie O'Hagan
Date
8/13/2026
led.FadeFromSecondColorToFirstColor();

◆ FadeToColor()

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.

Author
Eddie O'Hagan
Date
8/13/2026
led.FadeToColor(255, 0, 0, 255); //fade first color out while fading second color in.
Parameters
[in]startFirstColorValThe first color's starting PWM level.
[in]startSecondColorValThe second color's starting PWM level.
[in]endFirstColorValThe first color's target PWM level.
[in]endSecondColorValThe second color's target PWM level.

◆ GetFirstColorPinNumber()

unsigned int RumPi::DualLED::GetFirstColorPinNumber ( ) const

Gets the PWM pin for the first color.

Author
Eddie O'Hagan
Date
8/13/2026
int pin = led.GetFirstColorPinNumber();
Returns
The first color's PWM pin number.

◆ GetSecondColorPinNumber()

unsigned int RumPi::DualLED::GetSecondColorPinNumber ( ) const

Gets the PWM pin for the second color.

Author
Eddie O'Hagan
Date
8/13/2026
int pin = led.GetSecondColorPinNumber();
Returns
The second color's PWM pin number.

◆ ProcessRawValues()

void RumPi::DualLED::ProcessRawValues ( )
overridevirtual

Processes the LED's raw values.

Output-only, so there is nothing to read each cycle - this is a no-op.

Author
Eddie O'Hagan
Date
8/13/2026
led.ProcessRawValues(); //no-op for an output-only component.

Implements RumPi::BaseComponent.

◆ RunColorTest()

void RumPi::DualLED::RunColorTest ( )

Runs a short demo that cycles through the LED's on/off and fade behaviours, pausing between each step.

Author
Eddie O'Hagan
Date
8/13/2026
led.RunColorTest();

◆ ToString()

std::string RumPi::DualLED::ToString ( ) const
overridevirtual

Serializes the LED's two pin numbers to a string.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = led.ToString();
Returns
A string describing the LED.

Implements RumPi::BaseComponent.

◆ TurnColor()

void RumPi::DualLED::TurnColor ( const unsigned char  firstColorVal,
const unsigned char  secondColorVal 
)

Sets both colors' PWM levels at once (a blended color).

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnColor(200, 55);
Parameters
[in]firstColorValThe first color's PWM level (0-255).
[in]secondColorValThe second color's PWM level (0-255).

◆ TurnFirstColor()

void RumPi::DualLED::TurnFirstColor ( const unsigned char  firstColorVal)

Sets the first color's PWM level.

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnFirstColor(128); //half brightness.
Parameters
[in]firstColorValThe first color's PWM level (0-255).

◆ TurnOff()

void RumPi::DualLED::TurnOff ( )
overridevirtual

Turns the LED off: drives both colors to zero and stops soft PWM so the LED is actually off.

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnOff();

Implements RumPi::BaseComponent.

◆ TurnOffFirstColor()

void RumPi::DualLED::TurnOffFirstColor ( )

Drives the first color off.

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnOffFirstColor();

◆ TurnOffSecondColor()

void RumPi::DualLED::TurnOffSecondColor ( )

Drives the second color off.

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnOffSecondColor();

◆ TurnOn()

void RumPi::DualLED::TurnOn ( )
overridevirtual

Turns the LED on: (re)initializes PWM on both pins and drives both colors to full.

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnOn();

Implements RumPi::BaseComponent.

◆ TurnOnFirstColor()

void RumPi::DualLED::TurnOnFirstColor ( )

Drives the first color fully on.

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnOnFirstColor();

◆ TurnOnSecondColor()

void RumPi::DualLED::TurnOnSecondColor ( )

Drives the second color fully on.

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnOnSecondColor();

◆ TurnSecondColor()

void RumPi::DualLED::TurnSecondColor ( const unsigned char  secondColorVal)

Sets the second color's PWM level.

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnSecondColor(128); //half brightness.
Parameters
[in]secondColorValThe second color's PWM level (0-255).

Member Data Documentation

◆ myFirstColorPinNumber

unsigned int RumPi::DualLED::myFirstColorPinNumber
private

The PWM pin for the first color.

◆ myIsOn

bool RumPi::DualLED::myIsOn
private

True while the PWM pins are created/on, so TurnOn/TurnOff are idempotent (a repeat call is a no-op).

◆ mySecondColorPinNumber

unsigned int RumPi::DualLED::mySecondColorPinNumber
private

The PWM pin for the second color.


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