FastLED NeoPixel v1.0.3
Loading...
Searching...
No Matches
FastLED_NeoPixel.h
Go to the documentation of this file.
1/*
2 * Project FastLED NeoPixel Library
3 * @author David Madison
4 * @link github.com/dmadison/FastLED_NeoPixel
5 * @license MIT - Copyright (c) 2021 David Madison
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 */
26
27#ifndef FASTLED_NEOPIXEL_H
28#define FASTLED_NEOPIXEL_H
29
30#include <Arduino.h>
31
32#include <Adafruit_NeoPixel.h>
33#include <FastLED.h>
34
35
63public:
70 FastLED_NeoPixel_Variant(CRGB* ledPtr, uint16_t nLeds);
71
96 void begin(CLEDController& ctrl);
97
99 void show();
100
101
103 void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
104
106 void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
107
109 void setPixelColor(uint16_t n, uint32_t c);
110
112 void fill(uint32_t c = 0, uint16_t first = 0, uint16_t count = 0);
113
114
116 void setBrightness(uint8_t bright) { brightness = bright; }
117
119 void clear();
120
132 void updateLength(uint16_t n);
133
135 bool canShow();
136
137
139 uint8_t* getPixels() const { return (uint8_t*) leds; };
140
142 uint8_t getBrightness() const { return brightness; }
143
145 uint16_t numPixels() const { return numLEDs; }
146
148 uint32_t getPixelColor(uint16_t n) const;
149
150
152 static uint8_t sine8(uint8_t x) { return Adafruit_NeoPixel::sine8(x); }
153
155 static uint8_t gamma8(uint8_t x) { return Adafruit_NeoPixel::gamma8(x); }
156
157
159 static uint32_t Color(uint8_t r, uint8_t g, uint8_t b) { return Adafruit_NeoPixel::Color(r, g, b); }
160
162 static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { return Adafruit_NeoPixel::Color(r, g, b, w); }
163
165 static uint32_t ColorHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255) { return Adafruit_NeoPixel::ColorHSV(hue, sat, val); }
166
168 static uint32_t gamma32(uint32_t x) { return Adafruit_NeoPixel::gamma32(x); }
169
170
188 CRGB* getLeds() const { return leds; };
189
202 CLEDController* getController() const { return controller; }
203
213 static uint32_t Color(const CRGB& c) { return Adafruit_NeoPixel::Color(c.r, c.g, c.b); }
214
230 void setBlendWhite(bool blend) { blendWhite = blend; }
231
285 void setPin(uint16_t p);
286
295
298private:
305 CRGB packedToColor(uint32_t c) const;
306
307 CRGB* const leds;
308 const uint16_t maxLEDs;
309 uint16_t numLEDs;
310 CLEDController* controller = nullptr;
311
312 uint8_t brightness = 255;
313 uint32_t endTime;
314 bool blendWhite = false;
315};
316
317
348inline constexpr EOrder NeoToEOrder(uint32_t neoOrder) {
349 return
350 // FastLED Color Orders
351 neoOrder == ((uint32_t) RGB) ? RGB :
352 neoOrder == ((uint32_t) RBG) ? RBG :
353 neoOrder == ((uint32_t) GRB) ? GRB :
354 neoOrder == ((uint32_t) GBR) ? GBR :
355 neoOrder == ((uint32_t) BRG) ? BRG :
356 neoOrder == ((uint32_t) BGR) ? BGR :
357
358 // NeoPixel Color Orders at Speed 'NEO_KHZ800'
359 neoOrder == (NEO_RGB + NEO_KHZ800) ? RGB :
360 neoOrder == (NEO_RBG + NEO_KHZ800) ? RBG :
361 neoOrder == (NEO_GRB + NEO_KHZ800) ? GRB :
362 neoOrder == (NEO_GBR + NEO_KHZ800) ? GBR :
363 neoOrder == (NEO_BRG + NEO_KHZ800) ? BRG :
364 neoOrder == (NEO_BGR + NEO_KHZ800) ? BGR :
365
366 // NeoPixel Color Orders at Speed 'NEO_KHZ400'
367 neoOrder == (NEO_RGB + NEO_KHZ400) ? RGB :
368 neoOrder == (NEO_RBG + NEO_KHZ400) ? RBG :
369 neoOrder == (NEO_GRB + NEO_KHZ400) ? GRB :
370 neoOrder == (NEO_GBR + NEO_KHZ400) ? GBR :
371 neoOrder == (NEO_BRG + NEO_KHZ400) ? BRG :
372 neoOrder == (NEO_BGR + NEO_KHZ400) ? BGR :
373
374 GRB; // 'neoOrder' is not a valid color selection, using GRB as default
375}
376
377
412template<uint16_t NumLeds, uint8_t DataPin, uint32_t RgbOrder = GRB>
414public:
415 FastLED_NeoPixel() : FastLED_NeoPixel_Variant(ledData, NumLeds)
416 {
417 memset(ledData, 0, sizeof(ledData)); // set all LEDs to black
418 }
419
424 void begin() {
425 FastLED_NeoPixel_Variant::begin(FastLED.addLeds<WS2812B, DataPin, NeoToEOrder(RgbOrder)>(ledData, NumLeds));
426 }
427
429 uint8_t getPin() const { return DataPin; };
430
431private:
432 CRGB ledData[NumLeds];
433};
434
435
436#endif // FASTLED_NEOPIXEL_H
#define NEO_KHZ800
#define NEO_RBG
#define NEO_BGR
#define NEO_GRB
#define NEO_KHZ400
#define NEO_RGB
uint16_t neoPixelType
#define NEO_GBR
#define NEO_BRG
CFastLED FastLED
constexpr EOrder NeoToEOrder(uint32_t neoOrder)
Definition FastLED_NeoPixel.h:348
static uint32_t gamma32(uint32_t x)
static uint32_t ColorHSV(uint16_t hue, uint8_t sat=255, uint8_t val=255)
static uint8_t gamma8(uint8_t x)
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b)
static uint8_t sine8(uint8_t x)
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
FastLED implementation of the Adafruit_NeoPixel class. Base class for all strips.
Definition FastLED_NeoPixel.h:62
void fill(uint32_t c=0, uint16_t first=0, uint16_t count=0)
Definition FastLED_NeoPixel.cpp:71
static uint8_t sine8(uint8_t x)
Definition FastLED_NeoPixel.h:152
static uint32_t gamma32(uint32_t x)
Definition FastLED_NeoPixel.h:168
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b)
Definition FastLED_NeoPixel.h:159
void begin(CLEDController &ctrl)
Definition FastLED_NeoPixel.cpp:46
bool canShow()
Definition FastLED_NeoPixel.cpp:91
uint32_t getPixelColor(uint16_t n) const
Definition FastLED_NeoPixel.cpp:98
void clear()
Definition FastLED_NeoPixel.cpp:81
uint8_t * getPixels() const
Definition FastLED_NeoPixel.h:139
uint8_t getBrightness() const
Definition FastLED_NeoPixel.h:142
static uint32_t ColorHSV(uint16_t hue, uint8_t sat=255, uint8_t val=255)
Definition FastLED_NeoPixel.h:165
static uint8_t gamma8(uint8_t x)
Definition FastLED_NeoPixel.h:155
uint16_t numPixels() const
Definition FastLED_NeoPixel.h:145
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b)
Definition FastLED_NeoPixel.cpp:57
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w)
Definition FastLED_NeoPixel.h:162
void setBrightness(uint8_t bright)
Definition FastLED_NeoPixel.h:116
void show()
Definition FastLED_NeoPixel.cpp:50
void updateLength(uint16_t n)
Definition FastLED_NeoPixel.cpp:85
FastLED implementation of the Adafruit_NeoPixel class for WS2812B strips, with data.
Definition FastLED_NeoPixel.h:413
void begin()
Definition FastLED_NeoPixel.h:424
uint8_t getPin() const
Definition FastLED_NeoPixel.h:429
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
void setBlendWhite(bool blend)
Definition FastLED_NeoPixel.h:230
static uint32_t Color(const CRGB &c)
Definition FastLED_NeoPixel.h:213
CLEDController * getController() const
Definition FastLED_NeoPixel.h:202
CRGB * getLeds() const
Definition FastLED_NeoPixel.h:188
EOrder
RGB
BGR
BRG
GRB
RBG
GBR
void updateType(neoPixelType T)
void setPin(uint16_t p)
uint8_t r
uint8_t g
uint8_t b