This commit is contained in:
2017-09-15 18:02:46 +02:00
3 changed files with 54 additions and 23 deletions

View File

@@ -13,12 +13,22 @@ struct Color {
;
}
void set(const uint8_t r, const uint8_t g, const uint8_t b) {
Color(const uint8_t r, const uint8_t g, const uint8_t b) : r(r), g(g), b(b) {
;
}
void setRGB(const uint8_t r, const uint8_t g, const uint8_t b) {
this->r = r;
this->g = g;
this->b = b;
}
void setOff() {
this->r = 0;
this->g = 0;
this->b = 0;
}
void setHSV(const uint8_t h, const uint8_t s, const uint8_t v) {
uint8_t region, remainder, p, q, t;
@@ -66,18 +76,29 @@ template <int numLEDs> class WS2812B {
/** color-value for each attached LED */
Color colors[numLEDs];
/** enable/disable each led */
bool enabled[numLEDs] = {true};
public:
/** ctor */
WS2812B() {
LED_SET_PIN_TO_OUTPUT;
}
/** set the color for the given LED */
void setColor(const uint8_t idx, const Color rgb) {
colors[idx] = rgb;
colors[idx] = rgb;
}
/** enable/disable the given LED */
void setEnabled(const uint8_t idx, const bool en) {
enabled[idx] = en;
}
/** is the given LED enabled? */
bool isEnabled(const uint8_t idx) const {
return enabled[idx];
}
Color& getColor(const uint8_t idx) {
@@ -125,19 +146,24 @@ template <int numLEDs> class WS2812B {
// send0();
*/
// process each LED
for (uint8_t i = 0; i < numLEDs; ++i) {
const Color rgb = colors[i];
// process each LED
for (uint8_t i = 0; i < numLEDs; ++i) {
// send each LEDs 24-bit GRB data
sendByte(rgb.g);
sendByte(rgb.r);
sendByte(rgb.b);
if (enabled[i]) {
const Color rgb = colors[i];
sendByte(rgb.g);
sendByte(rgb.r);
sendByte(rgb.b);
} else {
sendByte(0);
sendByte(0);
sendByte(0);
}
}
}
reset();
reset();
// sei();