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

Neopixel Add 0mS timeout option for instant updates

Thanks @cymplecy
This commit is contained in:
Dave Conway-Jones 2018-11-25 18:44:01 +00:00
parent f1066285ae
commit 7f44a2af3d
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 76 additions and 52 deletions

View File

@ -62,10 +62,15 @@ def setPixel(strip, i, color):
def setPixels(strip, s, e, color, wait_ms=30): def setPixels(strip, s, e, color, wait_ms=30):
"""Set pixels from s(tart) to e(nd)""" """Set pixels from s(tart) to e(nd)"""
if (wait_ms > 0):
for i in range(s, e+1): for i in range(s, e+1):
strip.setPixelColor(i, color) strip.setPixelColor(i, color)
strip.show() strip.show()
time.sleep(wait_ms/1000.0) time.sleep(wait_ms/1000.0)
else:
for i in range(s, e+1):
strip.setPixelColor(i, color)
strip.show()
def setBrightness(strip, brightness, wait_ms=30): def setBrightness(strip, brightness, wait_ms=30):
"""Set overall brighness""" """Set overall brighness"""
@ -75,16 +80,22 @@ def setBrightness(strip, brightness, wait_ms=30):
def colorWipe(strip, color, wait_ms=30): def colorWipe(strip, color, wait_ms=30):
"""Wipe color across display a pixel at a time.""" """Wipe color across display a pixel at a time."""
if (wait_ms > 0):
for i in range(strip.numPixels()): for i in range(strip.numPixels()):
strip.setPixelColor(i, color) strip.setPixelColor(i, color)
strip.show() strip.show()
time.sleep(wait_ms/1000.0) time.sleep(wait_ms/1000.0)
else:
for i in range(strip.numPixels()):
strip.setPixelColor(i, color)
strip.show()
def shiftUp(strip, color, wait_ms=30): def shiftUp(strip, color, wait_ms=30):
"""Shift all pixels one way.""" """Shift all pixels one way."""
oldcolour = strip.getPixelColor(0) oldcolour = strip.getPixelColor(0)
strip.setPixelColor(0, color) strip.setPixelColor(0, color)
strip.show() strip.show()
if (wait_ms > 0):
time.sleep(wait_ms/1000.0) time.sleep(wait_ms/1000.0)
for i in range(1,LED_COUNT): for i in range(1,LED_COUNT):
newcolour = oldcolour newcolour = oldcolour
@ -92,12 +103,19 @@ def shiftUp(strip, color, wait_ms=30):
strip.setPixelColor(i, newcolour) strip.setPixelColor(i, newcolour)
strip.show() strip.show()
time.sleep(wait_ms/1000.0) time.sleep(wait_ms/1000.0)
else:
for i in range(1,LED_COUNT):
newcolour = oldcolour
oldcolour = strip.getPixelColor(i)
strip.setPixelColor(i, newcolour)
strip.show()
def shiftDown(strip, color, wait_ms=30): def shiftDown(strip, color, wait_ms=30):
"""Shift all pixels the other way.""" """Shift all pixels the other way."""
oldcolour = strip.getPixelColor(LED_COUNT-1) oldcolour = strip.getPixelColor(LED_COUNT-1)
strip.setPixelColor(LED_COUNT-1, color) strip.setPixelColor(LED_COUNT-1, color)
strip.show() strip.show()
if (wait_ms > 0):
time.sleep(wait_ms/1000.0) time.sleep(wait_ms/1000.0)
for i in range(LED_COUNT-2,-1,-1): for i in range(LED_COUNT-2,-1,-1):
newcolour = oldcolour newcolour = oldcolour
@ -105,6 +123,12 @@ def shiftDown(strip, color, wait_ms=30):
strip.setPixelColor(i, newcolour) strip.setPixelColor(i, newcolour)
strip.show() strip.show()
time.sleep(wait_ms/1000.0) time.sleep(wait_ms/1000.0)
else:
for i in range(LED_COUNT-2,-1,-1):
newcolour = oldcolour
oldcolour = strip.getPixelColor(i)
strip.setPixelColor(i, newcolour)
strip.show()
def wheel(pos): def wheel(pos):
"""Generate rainbow colors across 0-255 positions.""" """Generate rainbow colors across 0-255 positions."""

View File

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