This commit is contained in:
Robert K 2022-12-29 20:30:21 +01:00
parent 6a77947381
commit 84be424218
4 changed files with 41 additions and 42 deletions

View File

@ -20,79 +20,78 @@
#define ADAFRUIT_NEOPIXEL_H #define ADAFRUIT_NEOPIXEL_H
#if (ARDUINO >= 100) #if (ARDUINO >= 100)
#include <Arduino.h> #include <Arduino.h>
#else #else
#include <WProgram.h> #include <WProgram.h>
#include <pins_arduino.h> #include <pins_arduino.h>
#endif #endif
// 'type' flags for LED pixels (third parameter to constructor): // 'type' flags for LED pixels (third parameter to constructor):
#define NEO_RGB 0x00 // Wired for RGB data order #define NEO_RGB 0x00 // Wired for RGB data order
#define NEO_GRB 0x01 // Wired for GRB data order #define NEO_GRB 0x01 // Wired for GRB data order
#define NEO_BRG 0x04 #define NEO_BRG 0x04
#define NEO_COLMASK 0x01 #define NEO_COLMASK 0x01
#define NEO_KHZ800 0x02 // 800 KHz datastream #define NEO_KHZ800 0x02 // 800 KHz datastream
#define NEO_SPDMASK 0x02 #define NEO_SPDMASK 0x02
// Trinket flash space is tight, v1 NeoPixels aren't handled by default. // Trinket flash space is tight, v1 NeoPixels aren't handled by default.
// Remove the ifndef/endif to add support -- but code will be bigger. // Remove the ifndef/endif to add support -- but code will be bigger.
// Conversely, can comment out the #defines to save space on other MCUs. // Conversely, can comment out the #defines to save space on other MCUs.
#ifndef __AVR_ATtiny85__ #ifndef __AVR_ATtiny85__
#define NEO_KHZ400 0x00 // 400 KHz datastream #define NEO_KHZ400 0x00 // 400 KHz datastream
#endif #endif
class Adafruit_NeoPixel { class Adafruit_NeoPixel
{
public:
public:
// Constructor: number of LEDs, pin number, LED type // Constructor: number of LEDs, pin number, LED type
Adafruit_NeoPixel(uint16_t n, uint8_t p=6, uint8_t t=NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel(uint16_t n, uint8_t p = 6, uint8_t t = NEO_GRB + NEO_KHZ800);
~Adafruit_NeoPixel(); ~Adafruit_NeoPixel();
void void
begin(void), begin(void),
show(void), show(void),
setPin(uint8_t p), setPin(uint8_t p),
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b), setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b),
setPixelColor(uint16_t n, uint32_t c), setPixelColor(uint16_t n, uint32_t c),
setPixelColorHsv(uint16_t n, uint16_t h, uint8_t s, uint8_t v), setPixelColorHsv(uint16_t n, uint16_t h, uint8_t s, uint8_t v),
setBrightness(uint8_t), setBrightness(uint8_t),
clear(); clear();
uint8_t uint8_t
*getPixels(void) const, *
getBrightness(void) const; getPixels(void) const,
getBrightness(void) const;
uint16_t uint16_t
numPixels(void) const; numPixels(void) const;
static uint32_t static uint32_t
Color(uint8_t r, uint8_t g, uint8_t b); Color(uint8_t r, uint8_t g, uint8_t b);
uint32_t uint32_t
getPixelColor(uint16_t n) const; getPixelColor(uint16_t n) const;
inline bool inline bool
canShow(void) { return (micros() - endTime) >= 50L; } canShow(void) { return (micros() - endTime) >= 50L; }
private:
private:
const uint16_t const uint16_t
numLEDs, // Number of RGB LEDs in strip numLEDs, // Number of RGB LEDs in strip
numBytes; // Size of 'pixels' buffer below numBytes; // Size of 'pixels' buffer below
uint8_t uint8_t
pin, // Output pin number pin, // Output pin number
brightness, brightness,
*pixels, // Holds LED color values (3 bytes each) *pixels, // Holds LED color values (3 bytes each)
rOffset, // Index of red byte within each 3-byte pixel rOffset, // Index of red byte within each 3-byte pixel
gOffset, // Index of green byte gOffset, // Index of green byte
bOffset; // Index of blue byte bOffset; // Index of blue byte
const uint8_t const uint8_t
type; // Pixel flags (400 vs 800 KHz, RGB vs GRB color) type; // Pixel flags (400 vs 800 KHz, RGB vs GRB color)
uint32_t uint32_t
endTime; // Latch timing reference endTime; // Latch timing reference
#ifdef __AVR__ #ifdef __AVR__
const volatile uint8_t const volatile uint8_t
*port; // Output PORT register *port; // Output PORT register
uint8_t uint8_t
pinMask; // Output PORT bitmask pinMask; // Output PORT bitmask
#endif #endif
}; };
#endif // ADAFRUIT_NEOPIXEL_H #endif // ADAFRUIT_NEOPIXEL_H