mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Add neopixel array capability to Blinkstick node
This commit is contained in:
parent
4742e19202
commit
cba50b74a2
@ -71,7 +71,9 @@
|
|||||||
<li><b>"random"</b> will generate a random color</li>
|
<li><b>"random"</b> will generate a random color</li>
|
||||||
<li><i><a href="http://www.w3schools.com/html/html_colornames.asp" target="_new">Standard HTML color</a></i> name</li>
|
<li><i><a href="http://www.w3schools.com/html/html_colornames.asp" target="_new">Standard HTML color</a></i> name</li>
|
||||||
<li><b>object</b> can override any of the parameters</li>
|
<li><b>object</b> can override any of the parameters</li>
|
||||||
|
<li><b>array</b> of colours for a neopixel rgb strip - either name,name,... or r,g,b,r,g,b,... where r,g,b are 0 to 255.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<p>If using a neopixel strip it <i>must</i> be wired to the red or R channel of the blinkstick.</p>
|
||||||
<p>An object payload can override any of the settings on the node. Omitted parameters are left intact. For example:</p>
|
<p>An object payload can override any of the settings on the node. Omitted parameters are left intact. For example:</p>
|
||||||
<pre>
|
<pre>
|
||||||
{ 'color': 'blue' }
|
{ 'color': 'blue' }
|
||||||
|
@ -192,8 +192,42 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
if (typeof(msg.payload) === 'object' ) {
|
if (typeof(msg.payload) === 'object' ) {
|
||||||
|
// if it's an array then hopefully it's r,g,b,r,g,b or name,name,name
|
||||||
|
if (Array.isArray(msg.payload)) {
|
||||||
|
if (Object.size(node.led) !== 0) {
|
||||||
|
node.led.setMode(2); // put it into ws2812B LED mode
|
||||||
|
var data = [];
|
||||||
|
for (var i = 0; i < msg.payload.length; i++) {
|
||||||
|
if (typeof msg.payload[i] === "string") { // if string then assume must be colour names
|
||||||
|
var params = node.led.interpretParameters(msg.payload[i]); // lookup colour code from name
|
||||||
|
if (params) {
|
||||||
|
data.push(params.green);
|
||||||
|
data.push(params.red);
|
||||||
|
data.push(params.blue);
|
||||||
|
}
|
||||||
|
else { node.warn("invalid colour: "+msg.payload[i]); }
|
||||||
|
}
|
||||||
|
else { // otherwise lets use numbers 0-255
|
||||||
|
data.push(msg.payload[i+1]);
|
||||||
|
data.push(msg.payload[i]);
|
||||||
|
data.push(msg.payload[i+2]);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((data.length % 3) === 0) { // by now length must be a multiple of 3
|
||||||
|
node.led.setColors(0, data, function(err) {
|
||||||
|
if (err) { node.log(err); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
node.warn("Colour array length not / 3");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} // else if no blinkstick let it get caught below
|
||||||
|
}
|
||||||
|
// not an array - must be the "normal" object....
|
||||||
|
else {
|
||||||
var data = validatePayloadObject(msg.payload);
|
var data = validatePayloadObject(msg.payload);
|
||||||
|
|
||||||
if (typeof(data) === 'object') {
|
if (typeof(data) === 'object') {
|
||||||
node.task = data.task ? data.task : node.task;
|
node.task = data.task ? data.task : node.task;
|
||||||
node.delay = data.delay ? data.delay : node.delay;
|
node.delay = data.delay ? data.delay : node.delay;
|
||||||
@ -206,6 +240,7 @@ module.exports = function(RED) {
|
|||||||
node.error(data);
|
node.error(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if (p1.test(msg.payload)) {
|
} else if (p1.test(msg.payload)) {
|
||||||
//Color value is represented as "red,green,blue" string of bytes
|
//Color value is represented as "red,green,blue" string of bytes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-blinkstick",
|
"name" : "node-red-node-blinkstick",
|
||||||
"version" : "0.1.2",
|
"version" : "0.1.3",
|
||||||
"description" : "A Node-RED node to control a Blinkstick",
|
"description" : "A Node-RED node to control a Blinkstick",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"blinkstick" : "1.1.*"
|
"blinkstick" : "1.1.*"
|
||||||
|
Loading…
Reference in New Issue
Block a user