Adafruit_NeoPixel.h 2.7 KB

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