36 #ifndef ADAFRUIT_NEOPIXEL_H 37 #define ADAFRUIT_NEOPIXEL_H 42 #ifdef USE_TINYUSB // For Serial when selecting TinyUSB 43 #include <Adafruit_TinyUSB.h> 52 #if defined(ARDUINO_ARCH_RP2040) 54 #include "hardware/pio.h" 55 #include "hardware/clocks.h" 56 #include "rp2040_pio.h" 86 #define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2)) 87 #define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1)) 88 #define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) 89 #define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1)) 90 #define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0)) 91 #define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0)) 95 #define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3)) 96 #define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2)) 97 #define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3)) 98 #define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2)) 99 #define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1)) 100 #define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1)) 102 #define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3)) 103 #define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2)) 104 #define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3)) 105 #define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2)) 106 #define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1)) 107 #define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1)) 109 #define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3)) 110 #define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2)) 111 #define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3)) 112 #define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) 113 #define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1)) 114 #define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1)) 116 #define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0)) 117 #define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0)) 118 #define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0)) 119 #define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0)) 120 #define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0)) 121 #define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0)) 131 #define NEO_KHZ800 0x0000 132 #ifndef __AVR_ATtiny85__ 133 #define NEO_KHZ400 0x0100 158 static const uint8_t PROGMEM _NeoPixelSineTable[256] = {
159 128, 131, 134, 137, 140, 143, 146, 149, 152, 155, 158, 162, 165, 167, 170,
160 173, 176, 179, 182, 185, 188, 190, 193, 196, 198, 201, 203, 206, 208, 211,
161 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 234, 235, 237, 238, 240,
162 241, 243, 244, 245, 246, 248, 249, 250, 250, 251, 252, 253, 253, 254, 254,
163 254, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 252, 251,
164 250, 250, 249, 248, 246, 245, 244, 243, 241, 240, 238, 237, 235, 234, 232,
165 230, 228, 226, 224, 222, 220, 218, 215, 213, 211, 208, 206, 203, 201, 198,
166 196, 193, 190, 188, 185, 182, 179, 176, 173, 170, 167, 165, 162, 158, 155,
167 152, 149, 146, 143, 140, 137, 134, 131, 128, 124, 121, 118, 115, 112, 109,
168 106, 103, 100, 97, 93, 90, 88, 85, 82, 79, 76, 73, 70, 67, 65,
169 62, 59, 57, 54, 52, 49, 47, 44, 42, 40, 37, 35, 33, 31, 29,
170 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11, 10, 9, 7, 6,
171 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0,
172 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9, 10, 11,
173 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35, 37,
174 40, 42, 44, 47, 49, 52, 54, 57, 59, 62, 65, 67, 70, 73, 76,
175 79, 82, 85, 88, 90, 93, 97, 100, 103, 106, 109, 112, 115, 118, 121,
186 static const uint8_t PROGMEM _NeoPixelGammaTable[256] = {
187 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
188 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
189 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3,
190 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
191 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10,
192 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17,
193 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
194 25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34, 35,
195 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 48,
196 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
197 64, 65, 66, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 80, 81,
198 82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 96, 97, 99, 100, 102,
199 103, 105, 106, 108, 109, 111, 112, 114, 115, 117, 119, 120, 122, 124, 125,
200 127, 129, 130, 132, 134, 136, 137, 139, 141, 143, 145, 146, 148, 150, 152,
201 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182,
202 184, 186, 188, 191, 193, 195, 197, 199, 202, 204, 206, 209, 211, 213, 215,
203 218, 220, 223, 225, 227, 230, 232, 235, 237, 240, 242, 245, 247, 250, 252,
210 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) 211 extern "C" void espInit();
231 void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
232 void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
234 void fill(uint32_t c = 0, uint16_t first = 0, uint16_t count = 0);
268 uint32_t now = micros();
272 return (now -
endTime) >= 300L;
314 return pgm_read_byte(&_NeoPixelSineTable[x]);
328 return pgm_read_byte(&_NeoPixelGammaTable[x]);
341 static uint32_t
Color(uint8_t r, uint8_t g, uint8_t b) {
342 return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
356 static uint32_t
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
357 return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
359 static uint32_t
ColorHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255);
372 static uint32_t
gamma32(uint32_t x);
374 void rainbow(uint16_t first_hue = 0, int8_t reps = 1,
375 uint8_t saturation = 255, uint8_t
brightness = 255,
376 bool gammify =
true);
381 #if defined(ARDUINO_ARCH_RP2040) 382 bool rp2040claimPIO(
void);
383 void rp2040releasePIO(
void);
387 uint pio_program_offset = 0;
391 #ifdef NEO_KHZ400 // If 400 KHz NeoPixel support enabled... 408 volatile uint8_t *port;
412 #if defined(ARDUINO_ARCH_STM32) || \ 413 defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) || \ 414 defined(ARDUINO_ARCH_CH32) || \ 416 GPIO_TypeDef *gpioPort;
422 #endif // ADAFRUIT_NEOPIXEL_H #define NEO_GRB
Transmit as G,R,B.
Definition: Adafruit_NeoPixel.h:88
void fill(uint32_t c=0, uint16_t first=0, uint16_t count=0)
Fill all or part of the NeoPixel strip with a color.
Definition: Adafruit_NeoPixel.cpp:3470
uint16_t numBytes
Size of 'pixels' buffer below.
Definition: Adafruit_NeoPixel.h:397
uint16_t numLEDs
Number of RGB LEDs in strip.
Definition: Adafruit_NeoPixel.h:396
void updateLength(uint16_t n)
Change the length of a previously-declared Adafruit_NeoPixel strip object. Old data is deallocated an...
Definition: Adafruit_NeoPixel.cpp:176
Class that stores state and functions for interacting with Adafruit NeoPixels and compatible devices...
Definition: Adafruit_NeoPixel.h:219
uint8_t gOffset
Index of green byte.
Definition: Adafruit_NeoPixel.h:402
bool begin(void)
Configure NeoPixel pin for output.
Definition: Adafruit_NeoPixel.cpp:143
int16_t pin
Output pin number (-1 if not yet set)
Definition: Adafruit_NeoPixel.h:398
int16_t getPin(void) const
Retrieve the pin number used for NeoPixel data output.
Definition: Adafruit_NeoPixel.h:294
uint8_t brightness
Strip brightness 0-255 (stored as +1)
Definition: Adafruit_NeoPixel.h:399
uint16_t neoPixelType
3rd arg to Adafruit_NeoPixel constructor
Definition: Adafruit_NeoPixel.h:142
void show(void)
Transmit pixel data in RAM to NeoPixels.
Definition: Adafruit_NeoPixel.cpp:420
uint32_t endTime
Latch timing reference.
Definition: Adafruit_NeoPixel.h:405
bool is800KHz
true if 800 KHz pixels
Definition: Adafruit_NeoPixel.h:392
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b)
Set a pixel's color using separate red, green and blue components. If using RGBW pixels, white will be set to 0.
Definition: Adafruit_NeoPixel.cpp:3376
bool begun
true if begin() previously called successfully
Definition: Adafruit_NeoPixel.h:395
void setPin(int16_t p)
Set/change the NeoPixel output pin number. Previous pin, if any, is set to INPUT and the new pin is s...
Definition: Adafruit_NeoPixel.cpp:3338
void rainbow(uint16_t first_hue=0, int8_t reps=1, uint8_t saturation=255, uint8_t brightness=255, bool gammify=true)
Fill NeoPixel strip with one or more cycles of hues. Everyone loves the rainbow swirl so much...
Definition: Adafruit_NeoPixel.cpp:3736
uint8_t bOffset
Index of blue byte.
Definition: Adafruit_NeoPixel.h:403
uint8_t wOffset
Index of white (==rOffset if no white)
Definition: Adafruit_NeoPixel.h:404
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w)
Convert separate red, green, blue and white values into a single "packed" 32-bit WRGB color...
Definition: Adafruit_NeoPixel.h:356
static uint32_t gamma32(uint32_t x)
A gamma-correction function for 32-bit packed RGB or WRGB colors. Makes color transitions appear more...
Definition: Adafruit_NeoPixel.cpp:3703
void clear(void)
Fill the whole NeoPixel strip with 0 / black / off.
Definition: Adafruit_NeoPixel.cpp:3699
static uint32_t ColorHSV(uint16_t hue, uint8_t sat=255, uint8_t val=255)
Convert hue, saturation and value into a packed 32-bit RGB color that can be passed to setPixelColor(...
Definition: Adafruit_NeoPixel.cpp:3516
uint8_t * pixels
Holds LED color values (3 or 4 bytes each)
Definition: Adafruit_NeoPixel.h:400
uint32_t getPixelColor(uint16_t n) const
Query the color of a previously-set pixel.
Definition: Adafruit_NeoPixel.cpp:3603
void updateType(neoPixelType t)
Change the pixel format of a previously-declared Adafruit_NeoPixel strip object. If format changes fr...
Definition: Adafruit_NeoPixel.cpp:206
static neoPixelType str2order(const char *v)
Convert pixel color order from string (e.g. "BGR") to NeoPixel color order constant (e...
Definition: Adafruit_NeoPixel.cpp:3763
uint8_t * getPixels(void) const
Get a pointer directly to the NeoPixel data buffer in RAM. Pixel data is stored in a device-native fo...
Definition: Adafruit_NeoPixel.h:288
uint16_t numPixels(void) const
Return the number of pixels in an Adafruit_NeoPixel strip object.
Definition: Adafruit_NeoPixel.h:299
uint8_t rOffset
Red index within each 3- or 4-byte pixel.
Definition: Adafruit_NeoPixel.h:401
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b)
Convert separate red, green and blue values into a single "packed" 32-bit RGB color.
Definition: Adafruit_NeoPixel.h:341
bool canShow(void)
Check whether a call to show() will start sending data immediately or will 'block' for a required int...
Definition: Adafruit_NeoPixel.h:252
void setBrightness(uint8_t)
Adjust output brightness. Does not immediately affect what's currently displayed on the LEDs...
Definition: Adafruit_NeoPixel.cpp:3654
static uint8_t sine8(uint8_t x)
An 8-bit integer sine wave function, not directly compatible with standard trigonometric units like r...
Definition: Adafruit_NeoPixel.h:313
static uint8_t gamma8(uint8_t x)
An 8-bit gamma-correction function for basic pixel brightness adjustment. Makes color transitions app...
Definition: Adafruit_NeoPixel.h:327
~Adafruit_NeoPixel()
Deallocate Adafruit_NeoPixel object, set data pin back to INPUT.
Definition: Adafruit_NeoPixel.cpp:119
#define NEO_KHZ800
800 KHz data transmission
Definition: Adafruit_NeoPixel.h:131
Adafruit_NeoPixel(void)
"Empty" NeoPixel constructor when length, pin and/or pixel type are not known at compile-time, and must be initialized later with updateType(), updateLength() and setPin().
Definition: Adafruit_NeoPixel.cpp:107
uint8_t getBrightness(void) const
Retrieve the last-set brightness value for the strip.
Definition: Adafruit_NeoPixel.cpp:3694