forked from shanet/StairLights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdafruit_WS2801.h
65 lines (58 loc) · 2.13 KB
/
Adafruit_WS2801.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#include <pins_arduino.h>
#endif
// Not all LED pixels are RGB order; 36mm type expects GRB data.
// Optional flag to constructors indicates data order (default if
// unspecified is RGB). As long as setPixelColor/getPixelColor are
// used, other code can always treat 'packed' colors as RGB; the
// library will handle any required translation internally.
#define WS2801_RGB 0
#define WS2801_GRB 1
class Adafruit_WS2801 {
public:
// Configurable pins:
Adafruit_WS2801(uint16_t n, uint8_t dpin, uint8_t cpin, uint8_t order=WS2801_RGB);
Adafruit_WS2801(uint16_t x, uint16_t y, uint8_t dpin, uint8_t cpin, uint8_t order=WS2801_RGB);
// Use SPI hardware; specific pins only:
Adafruit_WS2801(uint16_t n, uint8_t order=WS2801_RGB);
// Empty constructor; init pins/strand length/data order later:
Adafruit_WS2801();
// Release memory (as needed):
~Adafruit_WS2801();
void
begin(void),
show(void),
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b),
setPixelColor(uint16_t n, uint32_t c),
setPixelColor(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b),
setPixelColor(uint16_t x, uint16_t y, uint32_t c),
updatePins(uint8_t dpin, uint8_t cpin), // Change pins, configurable
updatePins(void), // Change pins, hardware SPI
updateLength(uint16_t n), // Change strand length
updateOrder(uint8_t order); // Change data order
uint16_t
numPixels(void);
uint32_t
getPixelColor(uint16_t n);
private:
uint16_t
numLEDs,
width, // used with matrix mode
height; // used with matrix mode
uint8_t
*pixels, // Holds color values for each LED (3 bytes each)
rgb_order, // Color order; RGB vs GRB (or others, if needed in future)
clkpin , datapin, // Clock & data pin numbers
clkpinmask, datapinmask; // Clock & data PORT bitmasks
volatile uint8_t
*clkport , *dataport; // Clock & data PORT registers
void
alloc(uint16_t n),
startSPI(void);
boolean
hardwareSPI, // If 'true', using hardware SPI
begun; // If 'true', begin() method was previously invoked
};