1 #ifndef LEDPIXELENGINE_H
2 #define LEDPIXELENGINE_H
6 #define USE_LEDLIB 0 //0 for FastLED, 1 for Adafruit_NeoPixel, 2 for NeoPixelBus
8 #define USE_LEDLIB 1 //0 for FastLED, 1 for Adafruit_NeoPixel, 2 for NeoPixelBus
15 #include <Adafruit_NeoPixel.h>
17 #include <Adafruit_NeoPixel.h>
70 class FastLED_NeoPixel_Variant {
78 FastLED_NeoPixel_Variant(CRGB* ledPtr, uint16_t nLeds) :
110 void begin(CLEDController& ctrl)
118 if (fController !=
nullptr)
120 fController->show(fLED, fNumLEDs, fBrightness);
126 void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b)
130 fLED[n] = CRGB(r, g, b);
135 void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w)
137 setPixelColor(n, Color(r, g, b, w));
141 void setPixelColor(uint16_t n, uint32_t c)
145 fLED[n] = packedToColor(c);
150 void fill(uint32_t c = 0, uint16_t first = 0, uint16_t count = 0)
152 if (first >= fNumLEDs)
155 if (first == 0 && count == 0)
160 else if (first != 0 && count == 0)
163 count = fNumLEDs - first;
168 count = min(count, uint16_t(fNumLEDs - first));
171 fill_solid(fLED + first, count, packedToColor(c));
175 inline void setBrightness(uint8_t bright)
177 fBrightness = bright;
183 fill_solid(fLED, fNumLEDs, CRGB::Black);
197 void updateLength(uint16_t n)
209 if (fEndTime > micros())
213 return (micros() - fEndTime) >= 300UL;
217 inline uint8_t* getPixels()
const
219 return (uint8_t*)fLED;
223 inline uint8_t getBrightness()
const
229 inline uint16_t numPixels()
const
235 uint32_t getPixelColor(uint16_t n)
const
238 return Color(CRGB::Black);
239 return Color(fLED[n]);
243 static uint8_t sine8(uint8_t x) {
return Adafruit_NeoPixel::sine8(x); }
246 static uint8_t gamma8(uint8_t x) {
return Adafruit_NeoPixel::gamma8(x); }
250 static uint32_t Color(uint8_t r, uint8_t g, uint8_t b) {
return Adafruit_NeoPixel::Color(r, g, b); }
253 static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
return Adafruit_NeoPixel::Color(r, g, b, w); }
256 static uint32_t ColorHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255) {
return Adafruit_NeoPixel::ColorHSV(hue, sat, val); }
259 static uint32_t gamma32(uint32_t x) {
return Adafruit_NeoPixel::gamma32(x); }
279 inline CRGB* getLeds()
const
296 inline CLEDController* getController()
const
310 static uint32_t Color(
const CRGB& c)
312 return Adafruit_NeoPixel::Color(c.r, c.g, c.b);
330 void setBlendWhite(
bool blend)
388 void setPin(uint16_t p);
397 void updateType(neoPixelType T);
408 CRGB packedToColor(uint32_t c)
const
411 if (fBlendWhite ==
true)
412 color.addToRGB(c >> 24);
417 const uint16_t fMaxLEDs;
419 CLEDController* fController =
nullptr;
421 uint8_t fBrightness = 255;
423 bool fBlendWhite =
false;
457 inline constexpr EOrder NeoToEOrder(uint32_t neoOrder)
461 neoOrder == ((uint32_t) RGB) ? RGB :
462 neoOrder == ((uint32_t) RBG) ? RBG :
463 neoOrder == ((uint32_t) GRB) ? GRB :
464 neoOrder == ((uint32_t) GBR) ? GBR :
465 neoOrder == ((uint32_t) BRG) ? BRG :
466 neoOrder == ((uint32_t) BGR) ? BGR :
469 neoOrder == (NEO_RGB + NEO_KHZ800) ? RGB :
470 neoOrder == (NEO_RBG + NEO_KHZ800) ? RBG :
471 neoOrder == (NEO_GRB + NEO_KHZ800) ? GRB :
472 neoOrder == (NEO_GBR + NEO_KHZ800) ? GBR :
473 neoOrder == (NEO_BRG + NEO_KHZ800) ? BRG :
474 neoOrder == (NEO_BGR + NEO_KHZ800) ? BGR :
477 neoOrder == (NEO_RGB + NEO_KHZ400) ? RGB :
478 neoOrder == (NEO_RBG + NEO_KHZ400) ? RBG :
479 neoOrder == (NEO_GRB + NEO_KHZ400) ? GRB :
480 neoOrder == (NEO_GBR + NEO_KHZ400) ? GBR :
481 neoOrder == (NEO_BRG + NEO_KHZ400) ? BRG :
482 neoOrder == (NEO_BGR + NEO_KHZ400) ? BGR :
522 template<u
int16_t NUM_LEDS, u
int8_t DATA_PIN, u
int32_t RGB_ORDER = GRB>
523 class FastLED_NeoPixel :
public FastLED_NeoPixel_Variant {
525 FastLED_NeoPixel() : FastLED_NeoPixel_Variant(fLEDData, NUM_LEDS)
527 memset(fLEDData, 0,
sizeof(fLEDData));
536 FastLED_NeoPixel_Variant::begin(
537 FastLED.addLeds<WS2812B, DATA_PIN, NeoToEOrder(RGB_ORDER)>(fLEDData, NUM_LEDS));
541 inline uint8_t getPin()
const
547 CRGB fLEDData[NUM_LEDS];