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

An RGB LED driven by three PWM pins (red, green, blue). More...

#include <RGBLED.h>

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

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

Detailed Description

An RGB LED driven by three PWM pins (red, green, blue).

Supports named colors, arbitrary blends, and fading between colors.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ RGBLED()

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

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnWhite();
RGBLED(const unsigned int redPinNumber, const unsigned int greenPinNumber, const unsigned int bluePinNumber)
Builds an RGB LED on the three given PWM pins.
Definition: RGBLED.cpp:21
constexpr unsigned int PIN_GPIO_13
BCM GPIO pin 13.
Definition: Common.h:39
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]redPinNumberThe PWM pin for the red channel.
[in]greenPinNumberThe PWM pin for the green channel.
[in]bluePinNumberThe PWM pin for the blue channel.

◆ ~RGBLED()

RumPi::RGBLED::~RGBLED ( )
virtual

Destroys the LED, stopping soft PWM on all three pins.

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

Member Function Documentation

◆ FadeFromBlueToYellow()

void RumPi::RGBLED::FadeFromBlueToYellow ( )

Fades from blue to yellow.

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

◆ FadeFromGreenToBlue()

void RumPi::RGBLED::FadeFromGreenToBlue ( )

Fades from green to blue.

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

◆ FadeFromPurpleToRed()

void RumPi::RGBLED::FadeFromPurpleToRed ( )

Fades from purple to red.

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

◆ FadeFromRedToGreen()

void RumPi::RGBLED::FadeFromRedToGreen ( )

Fades from red to green.

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

◆ FadeToColor()

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.

Author
Eddie O'Hagan
Date
8/13/2026
led.FadeToColor(255, 0, 0, 0, 0, 255); //fade red to blue.
Parameters
[in]startRedValThe red channel's starting PWM level.
[in]startGreenValThe green channel's starting PWM level.
[in]startBlueValThe blue channel's starting PWM level.
[in]endRedValThe red channel's target PWM level.
[in]endGreenValThe green channel's target PWM level.
[in]endBlueValThe blue channel's target PWM level.

◆ GetBluePinNumber()

unsigned int RumPi::RGBLED::GetBluePinNumber ( ) const

Gets the PWM pin for the blue channel.

Author
Eddie O'Hagan
Date
8/13/2026
unsigned int pin = led.GetBluePinNumber();
Returns
The blue channel's PWM pin number.

◆ GetGreenPinNumber()

unsigned int RumPi::RGBLED::GetGreenPinNumber ( ) const

Gets the PWM pin for the green channel.

Author
Eddie O'Hagan
Date
8/13/2026
unsigned int pin = led.GetGreenPinNumber();
Returns
The green channel's PWM pin number.

◆ GetRedPinNumber()

unsigned int RumPi::RGBLED::GetRedPinNumber ( ) const

Gets the PWM pin for the red channel.

Author
Eddie O'Hagan
Date
8/13/2026
unsigned int pin = led.GetRedPinNumber();
Returns
The red channel's PWM pin number.

◆ ProcessRawValues()

void RumPi::RGBLED::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::RGBLED::RunColorTest ( )

Runs a short demo that cycles through the named colors and fades, pausing between each step.

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

◆ ToString()

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

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

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

Implements RumPi::BaseComponent.

◆ TurnBlack()

void RumPi::RGBLED::TurnBlack ( )

Drives the LED black (all channels off).

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

◆ TurnBlue()

void RumPi::RGBLED::TurnBlue ( )

Drives the LED blue.

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

◆ TurnColor()

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

Author
Eddie O'Hagan
Date
8/13/2026
led.TurnColor(128, 64, 200);
Parameters
[in]redValThe red channel's PWM level (0-255).
[in]greenValThe green channel's PWM level (0-255).
[in]blueValThe blue channel's PWM level (0-255).

◆ TurnGreen()

void RumPi::RGBLED::TurnGreen ( )

Drives the LED green.

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

◆ TurnOff()

void RumPi::RGBLED::TurnOff ( )
overridevirtual

Turns the LED off: drives it black and stops soft PWM on all three pins.

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

Implements RumPi::BaseComponent.

◆ TurnOn()

void RumPi::RGBLED::TurnOn ( )
overridevirtual

Turns the LED on: (re)initializes PWM on all three pins and drives it white.

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

Implements RumPi::BaseComponent.

◆ TurnPurple()

void RumPi::RGBLED::TurnPurple ( )

Drives the LED purple (red + blue).

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

◆ TurnRed()

void RumPi::RGBLED::TurnRed ( )

Drives the LED red.

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

◆ TurnWhite()

void RumPi::RGBLED::TurnWhite ( )

Drives the LED white (all channels full).

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

◆ TurnYellow()

void RumPi::RGBLED::TurnYellow ( )

Drives the LED yellow (red + green).

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

Member Data Documentation

◆ myBluePinNumber

unsigned int RumPi::RGBLED::myBluePinNumber
private

The PWM pin for the blue channel.

◆ myGreenPinNumber

unsigned int RumPi::RGBLED::myGreenPinNumber
private

The PWM pin for the green channel.

◆ myIsOn

bool RumPi::RGBLED::myIsOn
private

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

◆ myRedPinNumber

unsigned int RumPi::RGBLED::myRedPinNumber
private

The PWM pin for the red channel.


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