Adafruit WS2801 Library
Adafruit_WS2801.h
Go to the documentation of this file.
1 
5 #ifndef __ADAFRUIT_WS2801__
6 #define __ADAFRUIT_WS2801__
7 
8 #if (ARDUINO >= 100)
9 #include <Arduino.h>
10 #else
11 #include <WProgram.h>
12 #include <pins_arduino.h>
13 #endif
14 
15 // Not all LED pixels are RGB order; 36mm type expects GRB data.
16 // Optional flag to constructors indicates data order (default if
17 // unspecified is RGB). As long as setPixelColor/getPixelColor are
18 // used, other code can always treat 'packed' colors as RGB; the
19 // library will handle any required translation internally.
20 #define WS2801_RGB 0
21 #define WS2801_GRB 1
22 
23 
27 
28 public:
36  Adafruit_WS2801(uint16_t n, uint8_t dpin, uint8_t cpin,
37  uint8_t order = WS2801_RGB);
47  Adafruit_WS2801(uint16_t x, uint16_t y, uint8_t dpin, uint8_t cpin,
48  uint8_t order = WS2801_RGB);
54  Adafruit_WS2801(uint16_t n, uint8_t order = WS2801_RGB);
63 
64  void
68  begin(void),
72  show(void),
80  setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b),
86  setPixelColor(uint16_t n, uint32_t c),
95  setPixelColor(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b),
102  setPixelColor(uint16_t x, uint16_t y, uint32_t c),
106  clear(),
112  updatePins(uint8_t dpin, uint8_t cpin),
116  updatePins(void),
121  updateLength(uint16_t n),
126  updateOrder(uint8_t order);
127  uint16_t
132  numPixels(void);
133  uint32_t
139  getPixelColor(uint16_t n);
140 
141 private:
142  uint16_t numLEDs,
143  width, // used with matrix mode
144  height; // used with matrix mode
145  uint8_t *pixels, // Holds color values for each LED (3 bytes each)
146  rgb_order, // Color order; RGB vs GRB (or others, if needed in future)
147  clkpin, datapin; // Clock & data pin numbers
148 #ifdef __AVR__
149  uint8_t clkpinmask, datapinmask; // Clock & data PORT bitmasks
150  volatile uint8_t *clkport, *dataport; // Clock & data PORT registers
151 #endif
152  void alloc(uint16_t n), startSPI(void);
153  boolean hardwareSPI, // If 'true', using hardware SPI
154  begun; // If 'true', begin() method was previously invoked
155 };
156 
157 #endif // __ADAFRUIT_WS2801__
Adafruit_WS2801()
Empty constructor; init pins/strand length/data order later:
Definition: Adafruit_WS2801.cpp:98
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b)
Set pixel color from separate 8-bit R, G, B components.
Definition: Adafruit_WS2801.cpp:233
#define WS2801_RGB
Sets mode to RGB.
Definition: Adafruit_WS2801.h:20
void updateLength(uint16_t n)
Change strand length.
Definition: Adafruit_WS2801.cpp:184
void show(void)
Shows the pixels.
Definition: Adafruit_WS2801.cpp:199
void updateOrder(uint8_t order)
Change RGB data order.
Definition: Adafruit_WS2801.cpp:193
void clear()
Clear the entire string.
Definition: Adafruit_WS2801.cpp:297
void begin(void)
Activate SPI.
Definition: Adafruit_WS2801.cpp:113
void updatePins(void)
Change pin assignment post-constructor, switching to hardware SPI.
Definition: Adafruit_WS2801.cpp:124
~Adafruit_WS2801()
Release memory (as needed):
Definition: Adafruit_WS2801.cpp:107
uint16_t numPixels(void)
Returns the number of pixels currently connected.
Definition: Adafruit_WS2801.cpp:181
Class that stores state and functions for interacting with WS2801 LEDs.
Definition: Adafruit_WS2801.h:26
uint32_t getPixelColor(uint16_t n)
Query color from previously-set pixel.
Definition: Adafruit_WS2801.cpp:304