1D-pong/1D_pongESP32/Adafruit_NeoPixel.h

98 lines
3 KiB
C
Raw Normal View History

2022-12-29 20:29:06 +01:00
/*--------------------------------------------------------------------
This file is part of the Adafruit NeoPixel library.
NeoPixel is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#ifndef ADAFRUIT_NEOPIXEL_H
#define ADAFRUIT_NEOPIXEL_H
#if (ARDUINO >= 100)
2022-12-29 20:30:21 +01:00
#include <Arduino.h>
2022-12-29 20:29:06 +01:00
#else
2022-12-29 20:30:21 +01:00
#include <WProgram.h>
#include <pins_arduino.h>
2022-12-29 20:29:06 +01:00
#endif
// 'type' flags for LED pixels (third parameter to constructor):
2022-12-29 20:30:21 +01:00
#define NEO_RGB 0x00 // Wired for RGB data order
#define NEO_GRB 0x01 // Wired for GRB data order
#define NEO_BRG 0x04
2022-12-29 20:29:06 +01:00
#define NEO_COLMASK 0x01
2022-12-29 20:30:21 +01:00
#define NEO_KHZ800 0x02 // 800 KHz datastream
2022-12-29 20:29:06 +01:00
#define NEO_SPDMASK 0x02
// Trinket flash space is tight, v1 NeoPixels aren't handled by default.
// Remove the ifndef/endif to add support -- but code will be bigger.
// Conversely, can comment out the #defines to save space on other MCUs.
#ifndef __AVR_ATtiny85__
2022-12-29 20:30:21 +01:00
#define NEO_KHZ400 0x00 // 400 KHz datastream
2022-12-29 20:29:06 +01:00
#endif
2022-12-29 20:30:21 +01:00
class Adafruit_NeoPixel
{
2022-12-29 20:29:06 +01:00
2022-12-29 20:30:21 +01:00
public:
2022-12-29 20:29:06 +01:00
// Constructor: number of LEDs, pin number, LED type
2022-12-29 20:30:21 +01:00
Adafruit_NeoPixel(uint16_t n, uint8_t p = 6, uint8_t t = NEO_GRB + NEO_KHZ800);
2022-12-29 20:29:06 +01:00
~Adafruit_NeoPixel();
void
2022-12-29 20:30:21 +01:00
begin(void),
show(void),
setPin(uint8_t p),
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b),
setPixelColor(uint16_t n, uint32_t c),
setPixelColorHsv(uint16_t n, uint16_t h, uint8_t s, uint8_t v),
setBrightness(uint8_t),
clear();
2022-12-29 20:29:06 +01:00
uint8_t
2022-12-29 20:30:21 +01:00
*
getPixels(void) const,
getBrightness(void) const;
2022-12-29 20:29:06 +01:00
uint16_t
2022-12-29 20:30:21 +01:00
numPixels(void) const;
2022-12-29 20:29:06 +01:00
static uint32_t
2022-12-29 20:30:21 +01:00
Color(uint8_t r, uint8_t g, uint8_t b);
2022-12-29 20:29:06 +01:00
uint32_t
2022-12-29 20:30:21 +01:00
getPixelColor(uint16_t n) const;
2022-12-29 20:29:06 +01:00
inline bool
2022-12-29 20:30:21 +01:00
canShow(void) { return (micros() - endTime) >= 50L; }
2022-12-29 20:29:06 +01:00
2022-12-29 20:30:21 +01:00
private:
2022-12-29 20:29:06 +01:00
const uint16_t
2022-12-29 20:30:21 +01:00
numLEDs, // Number of RGB LEDs in strip
numBytes; // Size of 'pixels' buffer below
2022-12-29 20:29:06 +01:00
uint8_t
2022-12-29 20:30:21 +01:00
pin, // Output pin number
brightness,
*pixels, // Holds LED color values (3 bytes each)
rOffset, // Index of red byte within each 3-byte pixel
gOffset, // Index of green byte
bOffset; // Index of blue byte
2022-12-29 20:29:06 +01:00
const uint8_t
2022-12-29 20:30:21 +01:00
type; // Pixel flags (400 vs 800 KHz, RGB vs GRB color)
2022-12-29 20:29:06 +01:00
uint32_t
2022-12-29 20:30:21 +01:00
endTime; // Latch timing reference
2022-12-29 20:29:06 +01:00
#ifdef __AVR__
const volatile uint8_t
2022-12-29 20:30:21 +01:00
*port; // Output PORT register
2022-12-29 20:29:06 +01:00
uint8_t
2022-12-29 20:30:21 +01:00
pinMask; // Output PORT bitmask
2022-12-29 20:29:06 +01:00
#endif
};
#endif // ADAFRUIT_NEOPIXEL_H