mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Add needle mode to neopixel
This commit is contained in:
parent
d38c152983
commit
08164b5f9f
@ -29,6 +29,7 @@ Usage
|
||||
-----
|
||||
|
||||
Defaults to a bar chart style mode using configured foreground and background colours.
|
||||
It can also display a needle (single pixel) type gauge.
|
||||
|
||||
It can accept a number in **msg.payload** that can be either the number of pixels,
|
||||
or a percentage of the total length.
|
||||
|
@ -62,21 +62,29 @@ def colorWipe(strip, color, wait_ms=30):
|
||||
|
||||
def shiftUp(strip, color, wait_ms=30):
|
||||
"""Shift all pixels one way."""
|
||||
for i in range(strip.numPixels()):
|
||||
strip.setPixelColor(LED_COUNT-i, strip.getPixelColor(LED_COUNT-i-1))
|
||||
oldcolour = strip.getPixelColor(0)
|
||||
strip.setPixelColor(0, color)
|
||||
strip.show()
|
||||
time.sleep(wait_ms/1000.0)
|
||||
strip.setPixelColor(0,color)
|
||||
for i in range(1,LED_COUNT):
|
||||
newcolour = oldcolour
|
||||
oldcolour = strip.getPixelColor(i)
|
||||
strip.setPixelColor(i, newcolour)
|
||||
strip.show()
|
||||
time.sleep(wait_ms/1000.0)
|
||||
|
||||
def shiftDown(strip, color, wait_ms=30):
|
||||
"""Shift all pixels the other way."""
|
||||
for i in range(strip.numPixels()):
|
||||
strip.setPixelColor(i, strip.getPixelColor(i+1))
|
||||
oldcolour = strip.getPixelColor(LED_COUNT-1)
|
||||
strip.setPixelColor(LED_COUNT-1, color)
|
||||
strip.show()
|
||||
time.sleep(wait_ms/1000.0)
|
||||
strip.setPixelColor(LED_COUNT-1,color)
|
||||
for i in range(LED_COUNT-2,-1,-1):
|
||||
newcolour = oldcolour
|
||||
oldcolour = strip.getPixelColor(i)
|
||||
strip.setPixelColor(i, newcolour)
|
||||
strip.show()
|
||||
time.sleep(wait_ms/1000.0)
|
||||
|
||||
def wheel(pos):
|
||||
"""Generate rainbow colors across 0-255 positions."""
|
||||
|
@ -30,8 +30,10 @@
|
||||
<div class="form-row">
|
||||
<label for="node-input-mode"><i class="fa fa-cogs"></i> Mode</label>
|
||||
<select id="node-input-mode" style="width:73%">
|
||||
<option value="pcent">Percent of length</option>
|
||||
<option value="pixels">Number of pixels</option>
|
||||
<option value="pcent">Bar - Percent of length</option>
|
||||
<option value="pixels">Bar - Number of pixels</option>
|
||||
<option value="pcentneedle">Needle - Percent of length</option>
|
||||
<option value="pixelsneedle">Needle - Number of pixels</option>
|
||||
<option value="shiftu">Add pixel to start</option>
|
||||
<option value="shiftd">Add pixel to end</option>
|
||||
</select>
|
||||
@ -50,7 +52,9 @@
|
||||
<script type="text/x-red" data-help-name="rpi-neopixels">
|
||||
<p>Raspberry Pi node to drive a string of neopixel or ws2812 LEDs.</p>
|
||||
<p>Defaults to a bar chart style mode using configured foreground and background colours.
|
||||
It can accept a number in <b>msg.payload</b> that can be either the number of pixels, or a percentage of the total length.</p>
|
||||
It can also display a needle (single pixel) type gauge.</p>
|
||||
<p>It can accept a number in <b>msg.payload</b> that can be either the
|
||||
number of pixels, or a percentage of the total length.</p>
|
||||
<p>If you want to change the foregound colour, you can send a CSV of <i>html colour,length</i>.</p>
|
||||
<p>To set the background just send an <i>html colour</i> name.
|
||||
<a href="http://html-color-codes.info/color-names/" target="_top">Here
|
||||
|
@ -49,6 +49,7 @@ module.exports = function(RED) {
|
||||
this.wipe = Number(n.wipe || 40);
|
||||
if (this.wipe < 0) { this.wipe = 0; }
|
||||
var node = this;
|
||||
var needle = "255,255,255";
|
||||
var p1 = /^\#[A-Fa-f0-9]{6}$/
|
||||
var p2 = /^[0-9]+,[0-9]+,[0-9]+$/
|
||||
var p3 = /^[0-9]+,[0-9]+,[0-9]+,[0-9]+$/
|
||||
@ -62,12 +63,18 @@ module.exports = function(RED) {
|
||||
if (parts.length === 2) { // it's a colour and length
|
||||
if (isNaN(parseInt(parts[1]))) { parts = parts.reverse(); }
|
||||
if (colors.getRGB(parts[0])) {
|
||||
node.fgnd = colors.getRGB(parts[0]);
|
||||
var l = parts[1];
|
||||
if (node.mode === "pcent") { l = parseInt(l / 100 * node.pixels + 0.5); }
|
||||
if (node.mode.indexOf("pcent") >= 0) { l = parseInt(l / 100 * node.pixels + 0.5); }
|
||||
l = l - 1;
|
||||
if (node.mode.indexOf("need") >= 0) {
|
||||
needle = colors.getRGB(parts[0]);
|
||||
pay = "0,"+(l-1)+","+node.fgnd+"\n"+l+","+needle+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd;
|
||||
} else {
|
||||
node.fgnd = colors.getRGB(parts[0]);
|
||||
pay = "0,"+l+","+node.fgnd+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd;
|
||||
}
|
||||
console.log(pay);
|
||||
}
|
||||
else { node.warn("Invalid payload : "+pay); return; }
|
||||
}
|
||||
else {
|
||||
@ -80,12 +87,16 @@ module.exports = function(RED) {
|
||||
}
|
||||
else { // it's a single number so just draw bar
|
||||
var l = pay;
|
||||
if (node.mode === "pcent") { l = parseInt(l / 100 * node.pixels + 0.5); }
|
||||
if (node.mode.indexOf("pcent") >= 0) { l = parseInt(l / 100 * node.pixels + 0.5); }
|
||||
l = l - 1;
|
||||
if (node.mode.indexOf("need") >= 0) {
|
||||
pay = "0,"+(l-1)+","+node.fgnd+"\n"+l+","+needle+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd;
|
||||
} else {
|
||||
pay = "0,"+l+","+node.fgnd+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((parts.length <= 2) || p2.test(pay) || p3.test(pay) || p4.test(pay) ) {
|
||||
if (parts.length === 3) { node.bgnd = pay; }
|
||||
node.child.stdin.write(pay+"\n"); // handle 3 parts, 4 part and 5 parts in the python
|
||||
@ -136,8 +147,10 @@ module.exports = function(RED) {
|
||||
if (node.bgnd.split(',').length === 1) {
|
||||
node.bgnd = colors.getRGB(node.bgnd);
|
||||
}
|
||||
if (node.mode.indexOf("shift") === -1) {
|
||||
node.child.stdin.write(node.bgnd+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (node.fgnd) {
|
||||
if (node.fgnd.split(',').length === 1) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-pi-neopixel",
|
||||
"version" : "0.0.2",
|
||||
"version" : "0.0.3",
|
||||
"description" : "A Node-RED node to output to a neopixel (ws2812) string of LEDS from a Raspberry Pi.",
|
||||
"dependencies" : {
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user