RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RGBLED.h
Go to the documentation of this file.
1#pragma once
2#include <stdio.h>
3#include <wiringPi.h>
4#include <softPwm.h>
5#include "BaseComponent.h"
6
7namespace RumPi
8{
16 class RGBLED : public BaseComponent
17 {
18
19 private:
21 unsigned int myRedPinNumber;
22
24 unsigned int myGreenPinNumber;
25
27 unsigned int myBluePinNumber;
28
30 bool myIsOn;
31
32 public:
48 RGBLED(const unsigned int redPinNumber, const unsigned int greenPinNumber, const unsigned int bluePinNumber);
49
61 virtual ~RGBLED();
62
73 virtual void TurnOn() override;
74
85 virtual void TurnOff() override;
86
97 virtual void ProcessRawValues() override;
98
111 virtual std::string ToString() const override;
112
123 void TurnRed();
124
135 void TurnGreen();
136
147 void TurnBlue();
148
159 void TurnYellow();
160
171 void TurnPurple();
172
183 void TurnWhite();
184
195 void TurnBlack();
196
211 void TurnColor(const unsigned char redVal, const unsigned char greenVal, const unsigned char blueVal);
212
223 void FadeFromRedToGreen();
224
235 void FadeFromGreenToBlue();
236
248
259 void FadeFromPurpleToRed();
260
279 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);
280
291 void RunColorTest();
292
305 unsigned int GetRedPinNumber() const;
306
319 unsigned int GetGreenPinNumber() const;
320
333 unsigned int GetBluePinNumber() const;
334
335 };
336} // namespace RumPi
Abstract base class for every component (sensor, actuator, etc.) the library manages.
Definition: BaseComponent.h:60
An RGB LED driven by three PWM pins (red, green, blue).
Definition: RGBLED.h:17
void TurnBlue()
Drives the LED blue.
Definition: RGBLED.cpp:169
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...
Definition: RGBLED.cpp:333
unsigned int myGreenPinNumber
The PWM pin for the green channel.
Definition: RGBLED.h:24
void FadeFromBlueToYellow()
Fades from blue to yellow.
Definition: RGBLED.cpp:295
void FadeFromPurpleToRed()
Fades from purple to red.
Definition: RGBLED.cpp:310
void TurnWhite()
Drives the LED white (all channels full).
Definition: RGBLED.cpp:214
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
unsigned int GetBluePinNumber() const
Gets the PWM pin for the blue channel.
Definition: RGBLED.cpp:478
bool myIsOn
True while the PWM pins are created/on, so TurnOn/TurnOff are idempotent (a repeat call is a no-op).
Definition: RGBLED.h:30
virtual void TurnOff() override
Turns the LED off: drives it black and stops soft PWM on all three pins.
Definition: RGBLED.cpp:99
unsigned int GetRedPinNumber() const
Gets the PWM pin for the red channel.
Definition: RGBLED.cpp:444
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).
Definition: RGBLED.cpp:248
void TurnRed()
Drives the LED red.
Definition: RGBLED.cpp:139
unsigned int myBluePinNumber
The PWM pin for the blue channel.
Definition: RGBLED.h:27
void FadeFromRedToGreen()
Fades from red to green.
Definition: RGBLED.cpp:265
void RunColorTest()
Runs a short demo that cycles through the named colors and fades, pausing between each step.
Definition: RGBLED.cpp:401
unsigned int myRedPinNumber
The PWM pin for the red channel.
Definition: RGBLED.h:21
void FadeFromGreenToBlue()
Fades from green to blue.
Definition: RGBLED.cpp:280
void TurnPurple()
Drives the LED purple (red + blue).
Definition: RGBLED.cpp:199
virtual std::string ToString() const override
Serializes the LED's three pin numbers to a string.
Definition: RGBLED.cpp:495
virtual void ProcessRawValues() override
Processes the LED's raw values.
Definition: RGBLED.cpp:124
unsigned int GetGreenPinNumber() const
Gets the PWM pin for the green channel.
Definition: RGBLED.cpp:461
virtual ~RGBLED()
Destroys the LED, stopping soft PWM on all three pins.
Definition: RGBLED.cpp:45
void TurnGreen()
Drives the LED green.
Definition: RGBLED.cpp:154
void TurnYellow()
Drives the LED yellow (red + green).
Definition: RGBLED.cpp:184
void TurnBlack()
Drives the LED black (all channels off).
Definition: RGBLED.cpp:229
virtual void TurnOn() override
Turns the LED on: (re)initializes PWM on all three pins and drives it white.
Definition: RGBLED.cpp:62
RumPi is the library's top-level facade.
Definition: AlertManager.h:6