A simple class for driving an RGB LED that uses standard color specification.
RGBLed.cpp@1:f2ac6d53f63d, 2021-02-05 (annotated)
- Committer:
- jensva
- Date:
- Fri Feb 05 13:55:49 2021 +0000
- Revision:
- 1:f2ac6d53f63d
- Parent:
- 0:396b3f9574ea
Potentiometer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vandep01 | 0:396b3f9574ea | 1 | #include "RGBLed.h" |
vandep01 | 0:396b3f9574ea | 2 | |
vandep01 | 0:396b3f9574ea | 3 | RGBLed::RGBLed(PinName redPin, PinName greenPin, PinName bluePin) : m_red(redPin), m_green(greenPin), m_blue(bluePin) |
vandep01 | 0:396b3f9574ea | 4 | { |
vandep01 | 0:396b3f9574ea | 5 | } |
vandep01 | 0:396b3f9574ea | 6 | |
vandep01 | 0:396b3f9574ea | 7 | void RGBLed::init() |
vandep01 | 0:396b3f9574ea | 8 | { |
vandep01 | 0:396b3f9574ea | 9 | m_red.period(0.001); |
vandep01 | 0:396b3f9574ea | 10 | } |
vandep01 | 0:396b3f9574ea | 11 | |
vandep01 | 0:396b3f9574ea | 12 | void RGBLed::setColor(const float red, const float green, const float blue) |
vandep01 | 0:396b3f9574ea | 13 | { |
vandep01 | 0:396b3f9574ea | 14 | // Negative logic |
vandep01 | 0:396b3f9574ea | 15 | m_red = 1.f - red; |
vandep01 | 0:396b3f9574ea | 16 | m_green = 1.f - green; |
vandep01 | 0:396b3f9574ea | 17 | m_blue = 1.f - blue; |
vandep01 | 0:396b3f9574ea | 18 | } |