Skip to content

Commit b5cf46d

Browse files
committed
Add custom timing
1 parent a0c24d8 commit b5cf46d

File tree

3 files changed

+80
-119
lines changed

3 files changed

+80
-119
lines changed

documentation/drivers/neostrand/neostrand.md

Lines changed: 77 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ NeoStrand is subclass of NeoPixel, so we use the same constructor dictionary to
3333
const strand = new NeoStrand({length: 50, pin: 22, order: "RGB"});
3434
```
3535

36+
> Note: if you notice flicker, you may have to adjust the timing for your strip. Check your specification sheet. The durations are in 50ns increments. **NeoPixel** has been extended to allow custom timings.
37+
>
38+
```
39+
const Timing_WS2811 = {
40+
mark: { level0: 1, duration0: 800, level1: 0, duration1: 450, },
41+
space: { level0: 1, duration0: 400, level1: 0, duration1: 800, },
42+
reset: { level0: 0, duration0: 30000, level1: 0, duration1: 30000, } };
43+
>
44+
const strand = new NeoStrand({length: 50, pin: 22, order: "RGB",
45+
timing: Timing_WS2812B});
46+
```
47+
48+
 
49+
50+
> Note: You may want to tone down your lights during development so you don't blind yourself.
51+
>
52+
> ```js
53+
> strand.brightness(10);
54+
> ```
55+
> This diminishes your color range, so use with care. The default brightness is *64* and maximum is 255.
56+
3657
### Schemes
3758
3859
A scheme is a set of effects to apply to a strand. A scheme has one or more effects applied in the specified order. Setting the new scheme takes effect immediately, even if the strand is already running.
@@ -99,11 +120,12 @@ A [list of built-in effects](#builtin) can be found later in this document.
99120
| Parameter | default | range | description |
100121
|---|---|---|---|
101122
strand | (none) | | The NeoStrand to which this effect applied
102-
start | 0 | [0..strand.length] | index of first pixel of effect
103-
end | strand.length | [0..strand.length] | index of last pixel of effect
104-
duration | 1000 | | (ms) duration of one cycle of the effect
105-
reverse | 0 | [0, 1] | reverse effect
106-
loop | 1 | [0, 1] | loop the effect
123+
start | `0` | [0..strand.length] | The index of the first pixel of effect
124+
end | `strand.length` | [0..strand.length] | The index of the last pixel of effect
125+
size | `strand.length` | [0..strand.length] | The length of one hue cycle, in pixels
126+
duration | `1000` | | The duration of one complete cycle of the effect, in ms
127+
reverse | `0` | [0, 1] | Set to 1 to run the effect in reverse, i.e. run the timeline of the effect backwards
128+
loop | `1` | [0, 1] | Set to 1 to loop the effect
107129

108130
`start` and `end` define the span of pixels that this effect will operate on. `duration` is the length of one cycle of the effect.
109131

@@ -131,10 +153,12 @@ activate(effect) {
131153

132154
set effectValue(value) {
133155
for (let i=this.start; i<this.end; i++) {
134-
if (0 == (i % this.size))
135-
this.color = this.strand.makeRGB(Math.random() * this.max, Math.random() * this.max, Math.random() * this.max);
136-
this.strand.set(i, this.color, this.start, this.end);
137-
}
156+
//
157+
// For each pixel in the segment, perform the pixel operations
158+
// value will be in the range [ 0, effect.dur ] or whatever
159+
// range the effect specifies when it creates the timeline
160+
// in activate().
161+
// ...
138162
}
139163
}
140164
```
@@ -168,11 +192,12 @@ A `sizeA` and `sizeB` parameters define the pattern. For example { sizeA: 1, siz
168192
| Parameter | default | range | description |
169193
|---|---|---|---|
170194
strand | (none) | | The NeoStrand to which this effect applied
171-
start | 0 | [0..strand.length] | index of first pixel of effect
172-
end | strand.length | [0..strand.length] | index of last pixel of effect
173-
reverse | 0 | [0, 1] | reverse effect
174-
loop | 1 | [0, 1] | loop the effect
175-
duration | 1000 | | (ms) time of one complete cycle of the pattern
195+
start | `0` | [0..strand.length] | The index of the first pixel of effect
196+
end | `strand.length` | [0..strand.length] | The index of the last pixel of effect
197+
size | `strand.length` | [0..strand.length] | The length of one hue cycle, in pixels
198+
duration | 1000 | | time of one complete cycle of the pattern, in ms
199+
reverse | `0` | [0, 1] | Set to 1 to run the effect in reverse, i.e. run the timeline of the effect backwards
200+
loop | `1` | [0, 1] | Set to 1 to loop the effect
176201
sizeA | 1 | [1..strand.length] | number of pixels in the A part of pattern
177202
sizeB | 3 | [1..strand.length] | number of pixels in the B part of pattern
178203
rgbA | { r: 0, g: 0, b: 0x13 } | | RGB A color elements
@@ -188,12 +213,12 @@ The `HueSpan` effect is a smooth fade between colors. Like a color-wheel, it cyc
188213
| Parameter | default | range | description |
189214
|---|---|---|---|
190215
strand | (none) | | The NeoStrand to which this effect is applied
191-
start | 0 | [0..strand.length] | index of first pixel of effect
192-
end | strand.length | [0..strand.length] | index of last pixel of effect
193-
size | \<strand.length\> | [0..strand.length] | length of one hue cycle (in pixels)
194-
reverse | 0 | [0, 1] | reverse effect
195-
loop | 1 | [0, 1] | loop the effect
196-
duration | 1000 | | (ms) time of one complete color wheel cycle
216+
start | `0` | [0..strand.length] | The index of the first pixel of effect
217+
end | `strand.length` | [0..strand.length] | The index of the last pixel of effect
218+
size | `strand.length` | [0..strand.length] | The length of one hue cycle, in pixels
219+
duration | 1000 | | time of one complete cycle of the color wheel, in ms
220+
reverse | `0` | [0, 1] | Set to 1 to run the effect in reverse, i.e. run the timeline of the effect backwards
221+
loop | `1` | [0, 1] | Set to 1 to loop the effect
197222
speed | 1.0 | | speed multiplier
198223
position | 0 | [0..1] | starting HSV hue position
199224
saturation | 1.0 | [0..1] | HSV saturation
@@ -210,13 +235,12 @@ The `Sine` effect varys a color component in a sine wave fashion.
210235
| Parameter | default | range | description |
211236
|---|---|---|---|
212237
strand | (none) | | The NeoStrand to which this effect is applied
213-
start | 0 | [0..strand.length] | index of first pixel of effect
214-
end | strand.length | [0..strand.length] | index of last pixel of effect
215-
amplitude | 1 | [0..1] | amount of change (y axis multiplier)
216-
size | \<strand.length\> | [1..strand.length] | length of one cycle (0-2π radians) (in pixels)
217-
reverse | 0 | [0, 1] | reverse effect
218-
loop | 1 | [0, 1] | loop the effect
219-
duration | 1000 | | (ms) time of one complete sine cycle
238+
start | `0` | [0..strand.length] | The index of the first pixel of effect
239+
end | `strand.length` | [0..strand.length] | The index of the last pixel of effect
240+
size | `strand.length` | [0..strand.length] | The length of one hue cycle, in pixels
241+
duration | 1000 | | time of one complete sine cycle, in ms
242+
reverse | `0` | [0, 1] | Set to 1 to run the effect in reverse, i.e. run the timeline of the effect backwards
243+
loop | `1` | [0, 1] | Set to 1 to loop the effect
220244
speed | 1.0 | | speed multiplier
221245
loop | 1 | [0, 1] | loop the effect
222246
position | 0 | [0..1] | starting x position
@@ -233,14 +257,13 @@ The `Pulse` effect sets `size` number of pixels at a location and then moves it
233257
| Parameter | default | range | description |
234258
|---|---|---|---|
235259
strand | (none) | | The NeoStrand to which this effect is applied
236-
start | 0 | [0..strand.length] | index of first pixel of effect
237-
end | strand.length | [0..strand.length] | index of last pixel of effect
238-
size | 3 | [1..strand.length] | (pixels) size of a pulse
239-
reverse | 0 | [0, 1] | reverse effect
240-
loop | 1 | [0, 1] | loop the effect
241-
direction | 0 | [-1, 0, 1] | direction of effect
260+
start | `0` | [0..strand.length] | The index of the first pixel of effect
261+
end | `strand.length` | [0..strand.length] | The index of the last pixel of effect
262+
size | `strand.length` | [0..strand.length] | The length of one hue cycle, in pixels
263+
duration | 3000 | | time of one pulse cycle, in ms
264+
reverse | `0` | [0, 1] | Set to 1 to run the effect in reverse, i.e. run the timeline of the effect backwards
265+
loop | `1` | [0, 1] | Set to 1 to loop the effect
242266
position | "random" | [-strand.length..strand.length] | index of the pulse starting pixel<br>negative numbers are off-strand and okay<br>"random" picks a random starting location
243-
duration | 3000 | | (ms) time of one pulse cycle
244267
mode | 1 | [-1, 0, 1] | **1** to add, **-1** to subtract, or **0** set the pixel color
245268
fade | 0.2 | [0..1] | how quickly tails fade
246269
rgb | { r: 0x80, g: 0x80, b: 0x80 } | | RGB color elements
@@ -269,87 +292,8 @@ The `Dim` effect reduces the color for each pixel in the span over over the `dur
269292
strand | (none) | | The NeoStrand to which this effect is applied
270293
start | 0 | [0..strand.length] | index of first pixel of effect
271294
end | strand.length | [0..strand.length] | index of last pixel of effect
272-
duration | 1000 | | (ms) time to reduce a full-brightness pixel to off
273-
295+
duration | 1000 | | time to reduce a full-brightness pixel to off, in ms
274296
275-
<!--
276-
<a id="ease"></a>
277-
### Ease
278-
279-
The `Ease` effect uses the easing equations to move a pixel.
280-
281-
A `size` and `sizeB` parameters define the pattern. For example { sizeA: 1, sizeB: 3 } will produce the repeating pattern: [ A, B, B, B, A, B, B, B, A ... ]
282-
283-
| Parameter | default | range | description |
284-
|---|---|---|---|
285-
strand | (none) | | The NeoStrand to which this effect is applied
286-
start | (none) | [0..strand.length] | index of the first pixel of effect
287-
end | (none) | [0..strand.length] | index of the last pixel of effect
288-
size | 3 | [1..strand.length] | (pixels) size of a pulse
289-
reverse | 0 | [0, 1] | reverse effect
290-
loop | 1 | [0, 1] | loop the effect
291-
direction | 0 | [-1, 1] | direction of effect
292-
easing | null | | easing equation to use, null uses a linear easing function
293-
rgb | { r: 0x80, g: 0x80, b: 0x80 } | | RGB color elements
294-
295-
296-
<a id="bounce"></a>
297-
### Bounce
298-
299-
The `Bounce` effect bounces a small segment (ball) of pixels back and forth, erasing (setting to black) the pixel in the front and back of the ball.
300-
301-
| Parameter | default | description |
302-
|---|---|---|
303-
strand | (none) | The NeoStrand to which this effect is applied
304-
start | (none) | index of the first pixel of effect
305-
end | (none) | index of the last pixel of effect
306-
size | 3 | number of pixels of the 'ball'
307-
first | \<start\> | index of the pulse starting pixel<br>negative numbers are off-strand and okay<br>"random" picks a random starting location
308-
direction | 1 | starting direction of travel (1 or -1)
309-
speed | 1.0 | number of pixels traveled per iteration
310-
r, g, b | 0xff (white) | RGB color elements
311-
312-
313-
<a id="sparkle"></a>
314-
### Sparkle
315-
316-
The `Sparkle` effect applies a varying color value to a small segment of pixels. The pixels lighten and darken the color while gradually fading.
317-
318-
| Parameter | default | description |
319-
|---|---|---|
320-
strand | (none) | The NeoStrand to which this effect is applied
321-
start | (none) | index of the first pixel of effect
322-
end | (none) | index of the last pixel of effect
323-
size | 5 | number of pixels of the sparkle
324-
range | 100 | [0-255] how quickly the pixels fade (random from 0-range)
325-
decay | 15 | [0-255] how quickly the overall sparkle fades
326-
next | 500 | time (ms) between new sparkle locations
327-
r, g, b | 0xff (white) | RGB color elements
328-
329-
330-
<a id="fire"></a>
331-
### Fire
332-
333-
The `Fire` effect. Adapted from [Fire2012](https://blog.kriegsman.org/2014/04/04/fire2012-an-open-source-fire-simulation-for-arduino-and-leds/).
334-
335-
Fire is affected by three parameters. The first `cooling` controls how fast the flame cools down. More cooling means shorter flames. The recommended values are between 20 and 100.
336-
337-
The second `sparking` controls the chance (out of 255) that a spark will ignite. A higher value makes the fire more active. The recommended values are between 50 and 200.
338-
339-
The third `delay` controls the speed of fire activity. A higher value makes the flame flicker more slowly. The recommended values are between 0 and 20.
340-
341-
342-
| Parameter | default | description |
343-
|---|---|---|
344-
strand | (none) | The NeoStrand to which this effect is applied
345-
start | (none) | index of the first pixel of effect
346-
end | (none) | index of the last pixel of effect
347-
direction | 1 | starting direction of travel (1 or -1)
348-
cooling | 55 | [0-255] number of pixels of the sparkle
349-
sparking | 120 | [0-255] number of pixels of the sparkle
350-
delay | 15 | time (ms) between actions
351-
352-
-->
353297
354298
## Making a custom effect
355299
@@ -364,7 +308,7 @@ Let's make a random color effect. It will set `size` pixels to a random color, c
364308
strand | (none) | | The NeoStrand to which this effect is applied
365309
start | 0 | [0..strand.length] | index of first pixel of effect
366310
end | strand.length | [0..strand.length] | index of last pixel of effect
367-
duration | 1000 | | (ms) time between color changes
311+
duration | 1000 | | length time between color changes, in ms
368312
size | 5 | [0..strand.length] | size of each color
369313
max | 127 | [0..255] | maximium value of random RGB component
370314
@@ -405,5 +349,22 @@ class RandomColor extends NeoStrandEffect {
405349
Then create and add the effect your scheme list and give it a try.
406350
407351
```js
408-
schemes.push( [ new RandomColor( { strand } ) ]);
352+
let randomColorScheme = [ new RandomColor({ strand }) ];
353+
manySchemes.push( randomColorScheme );
409354
```
355+
356+
## Timing
357+
358+
Timing specifications for the various driver chips of the LEDs are included for reference below.
359+
360+
```js
361+
const Timing_WS2812B = {
362+
mark: { level0: 1, duration0: 900, level1: 0, duration1: 350, },
363+
space: { level0: 1, duration0: 350, level1: 0, duration1: 900, },
364+
reset: { level0: 0, duration0: 30000, level1: 0, duration1: 30000, } };
365+
366+
const Timing_WS2811 = {
367+
mark: { level0: 1, duration0: 800, level1: 0, duration1: 450, },
368+
space: { level0: 1, duration0: 400, level1: 0, duration1: 800, },
369+
reset: { level0: 0, duration0: 30000, level1: 0, duration1: 30000, } };
370+
```

modules/drivers/neopixel/esp32/modneopixel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ void xs_neopixel(xsMachine *the)
156156
xsmcGet(xsVar(2), xsVar(1), xsID_level1);
157157
bt->level1 = xsmcToInteger(xsVar(2));
158158
xsmcGet(xsVar(2), xsVar(1), xsID_duration0);
159-
bt->duration0 = xsmcToInteger(xsVar(2));
159+
bt->duration0 = xsmcToInteger(xsVar(2)) / RMT_PERIOD_NS;
160160
xsmcGet(xsVar(2), xsVar(1), xsID_duration1);
161-
bt->duration1 = xsmcToInteger(xsVar(2));
161+
bt->duration1 = xsmcToInteger(xsVar(2)) / RMT_PERIOD_NS;
162162
}
163163
}
164164
else {

modules/drivers/neostrand/neostrand.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class Marquee extends NeoStrandEffect {
192192
this.rgbA = this.strand.makeRGB(c.r, c.g, c.b);
193193
}
194194
else
195-
this.rgbA = this.strand.makeRGB(0, 0, 0x13);
195+
this.rgbA = this.strand.makeRGB(0, 0, 0x80);
196196

197197
if (dictionary.rgbB) {
198198
let c = dictionary.rgbB;

0 commit comments

Comments
 (0)