|
| 1 | +/*-------------------------------------------------------------------- |
| 2 | + This file is part of the Adafruit NeoPixel library. |
| 3 | +
|
| 4 | + NeoPixel is free software: you can redistribute it and/or modify |
| 5 | + it under the terms of the GNU Lesser General Public License as |
| 6 | + published by the Free Software Foundation, either version 3 of |
| 7 | + the License, or (at your option) any later version. |
| 8 | +
|
| 9 | + NeoPixel is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + GNU Lesser General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU Lesser General Public |
| 15 | + License along with NeoPixel. If not, see |
| 16 | + <http://www.gnu.org/licenses/>. |
| 17 | + --------------------------------------------------------------------*/ |
| 18 | + |
| 19 | +#ifndef ADAFRUIT_NEOPIXEL_H |
| 20 | +#define ADAFRUIT_NEOPIXEL_H |
| 21 | + |
| 22 | +#if (ARDUINO >= 100) |
| 23 | + #include <Arduino.h> |
| 24 | +#else |
| 25 | + #include <WProgram.h> |
| 26 | + #include <pins_arduino.h> |
| 27 | +#endif |
| 28 | + |
| 29 | +// 'type' flags for LED pixels (third parameter to constructor): |
| 30 | +#define NEO_RGB 0x00 // Wired for RGB data order |
| 31 | +#define NEO_GRB 0x01 // Wired for GRB data order |
| 32 | +#define NEO_BRG 0x04 |
| 33 | + |
| 34 | +#define NEO_COLMASK 0x01 |
| 35 | +#define NEO_KHZ800 0x02 // 800 KHz datastream |
| 36 | +#define NEO_SPDMASK 0x02 |
| 37 | +// Trinket flash space is tight, v1 NeoPixels aren't handled by default. |
| 38 | +// Remove the ifndef/endif to add support -- but code will be bigger. |
| 39 | +// Conversely, can comment out the #defines to save space on other MCUs. |
| 40 | +#ifndef __AVR_ATtiny85__ |
| 41 | +#define NEO_KHZ400 0x00 // 400 KHz datastream |
| 42 | +#endif |
| 43 | + |
| 44 | +class Adafruit_NeoPixel { |
| 45 | + |
| 46 | + public: |
| 47 | + |
| 48 | + // Constructor: number of LEDs, pin number, LED type |
| 49 | + Adafruit_NeoPixel(uint16_t n, uint8_t p=6, uint8_t t=NEO_GRB + NEO_KHZ800); |
| 50 | + ~Adafruit_NeoPixel(); |
| 51 | + |
| 52 | + void |
| 53 | + begin(void), |
| 54 | + show(void), |
| 55 | + setPin(uint8_t p), |
| 56 | + setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b), |
| 57 | + setPixelColor(uint16_t n, uint32_t c), |
| 58 | + setBrightness(uint8_t), |
| 59 | + clear(); |
| 60 | + uint8_t |
| 61 | + *getPixels(void) const, |
| 62 | + getBrightness(void) const; |
| 63 | + uint16_t |
| 64 | + numPixels(void) const; |
| 65 | + static uint32_t |
| 66 | + Color(uint8_t r, uint8_t g, uint8_t b); |
| 67 | + uint32_t |
| 68 | + getPixelColor(uint16_t n) const; |
| 69 | + inline bool |
| 70 | + canShow(void) { return (micros() - endTime) >= 50L; } |
| 71 | + |
| 72 | + private: |
| 73 | + |
| 74 | + const uint16_t |
| 75 | + numLEDs, // Number of RGB LEDs in strip |
| 76 | + numBytes; // Size of 'pixels' buffer below |
| 77 | + uint8_t |
| 78 | + pin, // Output pin number |
| 79 | + brightness, |
| 80 | + *pixels, // Holds LED color values (3 bytes each) |
| 81 | + rOffset, // Index of red byte within each 3-byte pixel |
| 82 | + gOffset, // Index of green byte |
| 83 | + bOffset; // Index of blue byte |
| 84 | + const uint8_t |
| 85 | + type; // Pixel flags (400 vs 800 KHz, RGB vs GRB color) |
| 86 | + uint32_t |
| 87 | + endTime; // Latch timing reference |
| 88 | +#ifdef __AVR__ |
| 89 | + const volatile uint8_t |
| 90 | + *port; // Output PORT register |
| 91 | + uint8_t |
| 92 | + pinMask; // Output PORT bitmask |
| 93 | +#endif |
| 94 | + |
| 95 | +}; |
| 96 | + |
| 97 | +#endif // ADAFRUIT_NEOPIXEL_H |
0 commit comments