RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
DualLED.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 DualLED : public BaseComponent
17 {
18
19 private:
20 /* WiringPi pin 0 is BCM_GPIO 17. we have to use BCM numbering when initializing
21 with wiringPiSetupSys when choosing a different pin number please use
22 the BCM numbering, also update the Property Pages - Build Events - Remote
23 Post-Build Event command which uses gpio export for setup for wiringPiSetupSys */
24
27
30
32 bool myIsOn;
33
34 public:
49 DualLED(const unsigned int firstColorPinNumber, const unsigned int secondColorPinNumber);
50
62 virtual ~DualLED();
63
74 virtual void TurnOn() override;
75
86 virtual void TurnOff() override;
87
98 virtual void ProcessRawValues() override;
99
112 virtual std::string ToString() const override;
113
124 void TurnOnFirstColor();
125
136 void TurnOnSecondColor();
137
148 void TurnOffFirstColor();
149
160 void TurnOffSecondColor();
161
174 void TurnFirstColor(const unsigned char firstColorVal);
175
188 void TurnSecondColor(const unsigned char secondColorVal);
189
203 void TurnColor(const unsigned char firstColorVal, const unsigned char secondColorVal);
204
216
228
245 void FadeToColor(const unsigned char startFirstColorVal, const unsigned char startSecondColorVal, const unsigned char endFirstColorVal, const unsigned char endSecondColorVal);
246
257 void RunColorTest();
258
271 unsigned int GetFirstColorPinNumber() const;
272
285 unsigned int GetSecondColorPinNumber() const;
286 };
287} // namespace RumPi
Abstract base class for every component (sensor, actuator, etc.) the library manages.
Definition: BaseComponent.h:60
A bi-color LED driven by two PWM pins (one per color).
Definition: DualLED.h:17
unsigned int GetSecondColorPinNumber() const
Gets the PWM pin for the second color.
Definition: DualLED.cpp:406
void RunColorTest()
Runs a short demo that cycles through the LED's on/off and fade behaviours, pausing between each step...
Definition: DualLED.cpp:357
virtual void TurnOff() override
Turns the LED off: drives both colors to zero and stops soft PWM so the LED is actually off.
Definition: DualLED.cpp:160
void TurnFirstColor(const unsigned char firstColorVal)
Sets the first color's PWM level.
Definition: DualLED.cpp:217
void FadeFromFirstToSecondColor()
Fades from the first color fully on to the second color fully on.
Definition: DualLED.cpp:268
unsigned int myFirstColorPinNumber
The PWM pin for the first color.
Definition: DualLED.h:26
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.
Definition: DualLED.cpp:304
virtual std::string ToString() const override
Serializes the LED's two pin numbers to a string.
Definition: DualLED.cpp:110
void FadeFromSecondColorToFirstColor()
Fades from the second color fully on to the first color fully on.
Definition: DualLED.cpp:283
void TurnColor(const unsigned char firstColorVal, const unsigned char secondColorVal)
Sets both colors' PWM levels at once (a blended color).
Definition: DualLED.cpp:252
void TurnOffFirstColor()
Drives the first color off.
Definition: DualLED.cpp:185
void TurnOnSecondColor()
Drives the second color fully on.
Definition: DualLED.cpp:145
virtual void ProcessRawValues() override
Processes the LED's raw values.
Definition: DualLED.cpp:94
void TurnOnFirstColor()
Drives the first color fully on.
Definition: DualLED.cpp:130
bool myIsOn
True while the PWM pins are created/on, so TurnOn/TurnOff are idempotent (a repeat call is a no-op).
Definition: DualLED.h:32
void TurnOffSecondColor()
Drives the second color off.
Definition: DualLED.cpp:200
unsigned int GetFirstColorPinNumber() const
Gets the PWM pin for the first color.
Definition: DualLED.cpp:389
virtual void TurnOn() override
Turns the LED on: (re)initializes PWM on both pins and drives both colors to full.
Definition: DualLED.cpp:60
DualLED(const unsigned int firstColorPinNumber, const unsigned int secondColorPinNumber)
Builds a dual-color LED on the two given PWM pins.
Definition: DualLED.cpp:20
unsigned int mySecondColorPinNumber
The PWM pin for the second color.
Definition: DualLED.h:29
virtual ~DualLED()
Destroys the LED, stopping soft PWM on both pins.
Definition: DualLED.cpp:44
void TurnSecondColor(const unsigned char secondColorVal)
Sets the second color's PWM level.
Definition: DualLED.cpp:234
RumPi is the library's top-level facade.
Definition: AlertManager.h:6