You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-32
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# WS2812 v2.0.2
1
+
# WS2812 3.0.0
2
2
3
3
This class allows the imp to drive WS2812 and WS2812B LEDs. The WS2812 is an all-in-one RGB LED with integrated shift register and constant-current driver. The parts are daisy-chained, and a proprietary one-wire protocol is used to send data to the chain of LEDs. Each pixel is individually addressable and this allows the part to be used for a wide range of effects animations.
4
4
@@ -9,18 +9,18 @@ Some example hardware that uses the WS2812 or WS2812B:
9
9
*[30 LED - 1m strip](http://www.adafruit.com/products/1376)
**To add this library to your project, add `#require "WS2812.class.nut:2.0.2"` to the top of your device code.**
13
-
14
-
You can view the library’s source code on [GitHub](https://github.com/electricimp/ws2812/tree/v2.0.2).
12
+
**To add this library to your project, add**`#require "WS2812.class.nut:3.0.0"`**to the top of your device code.**
15
13
16
14
## Hardware
17
15
18
-
WS2812s require a 5V power supply and logic, and each pixel can draw up to 60mA when displaying white in full brightness, so be sure to size your power supply appropriatly. Undersized power supplies (lower voltages and/or insufficent current) can cause glitches and/or failure to produce and light at all.
16
+
WS2812s require a 5V power supply and logic, and each pixel can draw up to 60mA when displaying white in full brightness, so be sure to size your power supply appropriately. Undersized power supplies (lower voltages and/or insufficient current) can cause glitches and/or failure to produce and light at all.
19
17
20
18
Because WS2812s require 5V logic, you will need to shift your logic level to 5V. A sample circuit can be found below using Adafruit’s [4-channel Bi-directional Logic Level Converter](http://www.adafruit.com/products/757):
21
19
22
20

23
21
22
+
**Warning** We do not recommend using the imp005 with WS2812s. Unlike the imp001, imp002, imp003 and imp004m, the imp005 does not use DMA for SPI data transfers. Instead, each byte is written out individually, and this means there will always be a small gap between each byte. As a result, the LEDs may not work as expected and the performance of other operations, such as Agent/Device communications, are blocked when the *draw()* method is called.
23
+
24
24
## Class Usage
25
25
26
26
All public methods in the WS2812 class return `this`, allowing you to easily chain multiple commands together:
Instantiate the class with a pre-configured SPI object and the number of pixels that are connected. The SPI object must be configured at 7500kHz and have the *MSB_FIRST* flag set:
38
+
Instantiate the class with an imp SPI object and the number of pixels that are connected. The SPI object will be configured by the constructor. An optional third parameter can be set to control whether the class will draw an empty frame on initialization. The default value is `true`.
39
39
40
40
```squirrel
41
-
#require "ws2812.class.nut:2.0.2"
41
+
#require "ws2812.class.nut:3.0.0"
42
42
43
-
// Configure the SPI bus
43
+
// Select the SPI bus
44
44
spi <- hardware.spi257;
45
-
spi.configure(MSB_FIRST, 7500);
46
45
47
46
// Instantiate LED array with 5 pixels
48
47
pixels <- WS2812(spi, 5);
49
48
```
50
49
51
-
An optional third parameter can be set to control whether the class will draw an empty frame on initialization. The default value is `true`.
52
-
53
50
## Class Methods
54
51
55
-
### configure()
56
-
57
-
Rather than pass a preconfigured SPI object to the constructor, you can pass an unconfigured SPI object, and have the *configure()* method automatically configure the SPI object for you.
58
-
59
-
**NOTE:** If you are using the *configure* method, you **must** pass `false` the the *draw* parameter of the constructor:
60
-
61
-
```squirrel
62
-
#require "ws2812.class.nut:2.0.2"
63
-
64
-
// Create and configure an LED array with 5 pixels:
The *set* method changes the color of a particular pixel in the frame buffer. The color is passed as as an array of three integers between 0 and 255 representing `[red, green, blue]`.
54
+
The *set()* method changes the color of a particular pixel in the frame buffer. The color is passed as as an array of three integers between 0 and 255 representing `[red, green, blue]`.
71
55
72
-
NOTE: The *set* method does not output the changes to the pixel strip. After setting up the frame, you must call `draw` (see below) to output the frame to the strip.
56
+
**Note** The *set()* method does not output the changes to the pixel strip. After setting up the frame, you must call *draw()* (see below) to output the frame to the strip.
73
57
74
58
```squirrel
75
59
// Set and draw a pixel
76
60
pixels.set(0, [127,0,0]).draw();
77
61
```
78
62
79
-
### fill(*color, [start], [end]*)
63
+
### fill(*color[, start][, end]*)
80
64
81
-
The *fill* methods sets all pixels in the specified range to the desired color. If no range is selected, the entire frame will be filled with the specified color.
65
+
The *fill()* method sets all pixels in the specified range to the desired color. If no range is selected, the entire frame will be filled with the specified color.
82
66
83
-
NOTE: The *fill* method does not output the changes to the pixel strip. After setting up the frame, you must call `draw` (see below) to output the frame to the strip.
67
+
**Note** The *fill()* method does not output the changes to the pixel strip. After setting up the frame, you must call *draw()* (see below) to output the frame to the strip.
84
68
85
69
```squirrel
86
70
// Turn all LEDs off
@@ -92,13 +76,13 @@ pixels.fill([0,0,0]).draw();
92
76
// and the other half blue
93
77
pixels
94
78
.fill([100,0,0], 0, 2)
95
-
.fill([0,0,100], 3, 4);
79
+
.fill([0,0,100], 3, 4)
96
80
.draw();
97
81
```
98
82
99
83
### draw()
100
84
101
-
The *draw* method draws writes the current frame to the pixel array (see examples above).
85
+
The *draw()* method draws writes the current frame to the pixel array (see examples above).
0 commit comments