1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Add Shift modes to neopixel node

This commit is contained in:
Dave Conway-Jones 2016-01-12 22:53:43 +00:00
parent 4ed955cecf
commit d38c152983
5 changed files with 57 additions and 15 deletions

View File

@ -2,14 +2,15 @@ node-red-node-pi-neopixel
=========================
A <a href="http://nodered.org" target="_new">Node-RED</a> node to drive a strip
of Neopixel or WS2812 LEDs.
of Neopixel or WS2812 LEDs from a Raspberry Pi.
Pre-requisites
--------------
The Unicorn HAT python drivers need to be pre-installed... This is the easiest way to get the neopixel driver installed... see the
<a "href=http://learn.pimoroni.com/tutorial/unicorn-hat/getting-started-with-unicorn-hat">
Pimorini Getting Started with Unicorn HAT</a> page.
The Neopixel python driver need to be pre-installed... The easiest way to get
the driver installed is to use the Unicorn HAT drivers install script... see the
<a href="http://learn.pimoroni.com/tutorial/unicorn-hat/getting-started-with-unicorn-hat" target="_new">
Pimoroni Getting Started with Unicorn HAT</a> page.
curl -sS get.pimoroni.com/unicornhat | bash
@ -21,22 +22,29 @@ Usually this is `~/.node-red`
npm install node-red-node-pi-neopixel
The data pin of the pixels should be connected to physical pin 12 - GPIO 18 of the Pi.
*Note:* this may conflict with audio playback.
Usage
-----
Defaults to a bar chart style mode using configured foreground and background colours.
It can accept a number in **msg.payload** that can be either the number of pixels, or a percentage of the total length.
It can accept a number in **msg.payload** that can be either the number of pixels,
or a percentage of the total length.
If you want to change the foregound colour, you can set **msg.payload** to a comma separated string of `html_colour,length`.
If you want to change the foreground colour, you can set **msg.payload** to a
comma separated string of `html_colour,length` or `length,html_colour`
To set the background just set **msg.payload** `html_colour` name.
To set the background just set **msg.payload** to an `html_colour` name.
<a href="http://html-color-codes.info/color-names/" target="_top">Here
is a list</a> of html_colour names.
The `nth` pixel is set by **msg.payload** with a CSV string `n,r,g,b`
You can also select shift modes where a single colour pixel is added to either
the start or the end of the strip, shifting all the others along by one.
The `nth` pixel can be set by **msg.payload** with a CSV string `n,r,g,b` ,
where r, g and b are 0-255.
A range of pixels from `x` to `y` can be set by **msg.payload**
with a CSV string `x,y,r,g,b`
The pixels data line should be connected to Pi physical pin 12 - GPIO 18. *Note:* this may conflict with audio playback.

View File

@ -32,6 +32,13 @@ if sys.version_info >= (3,0):
LED_COUNT = int(sys.argv[1])
WAIT_MS = int(sys.argv[2])
MODE = sys.argv[3]
def getRGBfromI(RGBint):
blue = RGBint & 255
green = (RGBint >> 8) & 255
red = (RGBint >> 16) & 255
return red, green, blue
# Define functions which animate LEDs in various ways.
def setPixel(strip, i, color):
@ -53,6 +60,24 @@ def colorWipe(strip, color, wait_ms=30):
strip.show()
time.sleep(wait_ms/1000.0)
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))
strip.show()
time.sleep(wait_ms/1000.0)
strip.setPixelColor(0,color)
strip.show()
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))
strip.show()
time.sleep(wait_ms/1000.0)
strip.setPixelColor(LED_COUNT-1,color)
strip.show()
def wheel(pos):
"""Generate rainbow colors across 0-255 positions."""
if pos < 85:
@ -103,12 +128,18 @@ if __name__ == '__main__':
data = raw_input()
bits = data.split(',')
if len(bits) == 3:
colorWipe(strip, Color(int(bits[0]), int(bits[1]), int(bits[2])), WAIT_MS)
if len(bits) == 4:
if MODE == "shiftu":
shiftUp(strip, Color(int(bits[0]), int(bits[1]), int(bits[2])), WAIT_MS)
elif MODE == "shiftd":
shiftDown(strip, Color(int(bits[0]), int(bits[1]), int(bits[2])), WAIT_MS)
else:
colorWipe(strip, Color(int(bits[0]), int(bits[1]), int(bits[2])), WAIT_MS)
if (MODE[0] == 'p' and len(bits) == 4):
setPixel(strip, int(bits[0]), Color(int(bits[1]), int(bits[2]), int(bits[3]) ))
if len(bits) == 5:
if (MODE[0] == 'p' and len(bits) == 5):
setPixels(strip, int(bits[0]), int(bits[1]), Color(int(bits[2]), int(bits[3]), int(bits[4]) ), WAIT_MS)
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
sys.exit(0)
except Exception as ex:
print "bad data: "+data
print ex

View File

@ -32,6 +32,8 @@
<select id="node-input-mode" style="width:73%">
<option value="pcent">Percent of length</option>
<option value="pixels">Number of pixels</option>
<option value="shiftu">Add pixel to start</option>
<option value="shiftd">Add pixel to end</option>
</select>
</div>
<div class="form-row">
@ -53,6 +55,7 @@
<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
is a list</a> of html colour names.<p>
<p>You can also select shift modes where a single colour pixel is added to either the start or the end of the strip.</p>
<p>The <i>nth</i> pixel is set by <b>msg.payload</b> with a CSV string <i>n,r,g,b</i>
<!-- <p>The whole strip is set by <b>msg.payload</b> with a CSV string <i>r,g,b</i> -->
<p>A range of pixels from <i>x</i> to <i>y</i> can be set by <b>msg.payload</b>

View File

@ -94,7 +94,7 @@ module.exports = function(RED) {
}
}
node.child = spawn(piCommand, [node.pixels, node.wipe]);
node.child = spawn(piCommand, [node.pixels, node.wipe, node.mode]);
node.status({fill:"green",shape:"dot",text:"ok"});
node.on("input", inputlistener);

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-pi-neopixel",
"version" : "0.0.1",
"version" : "0.0.2",
"description" : "A Node-RED node to output to a neopixel (ws2812) string of LEDS from a Raspberry Pi.",
"dependencies" : {
},