Try this. Will be extending BlinkStickPro class to include these helper functions.
import time
import math
import colorsys
from random import randint
from blinkstick import blinkstick
class Main(blinkstick.BlinkStickPro):
def set_color_all(self, channel, red, green, blue, remap_values=True):
"""
Set the color of all pixels
@type channel: int
@param channel: R, G or B channel
@type r: int
@param r: red color byte
@type g: int
@param g: green color byte
@type b: int
@param b: blue color byte
"""
if remap_values:
red, green, blue = [blinkstick._remap_color(val, self.max_rgb_value) for val in [red, green, blue]]
for i in range(0, self.r_led_count):
self.data[channel][i] = [green, red, blue]
def morph_all(self, channel, red=0, green=0, blue=0, name=None, hex=None, duration=1000, steps=50):
"""
Morph to the specified color for all pixels.
@type channel: int
@param channel: R, G or B channel
@type red: int
@param red: Red color intensity 0 is off, 255 is full red intensity
@type green: int
@param green: Green color intensity 0 is off, 255 is full green intensity
@type blue: int
@param blue: Blue color intensity 0 is off, 255 is full blue intensity
@type name: str
@param name: Use CSS color name as defined here: U{http://www.w3.org/TR/css3-color/}
@type hex: str
@param hex: Specify color using hexadecimal color value e.g. '#FF3366'
@type duration: int
@param duration: Duration for morph in milliseconds
@type steps: int
@param steps: Number of gradient steps (default 50)
"""
r_end, g_end, b_end = self.bstick._determine_rgb(red=red, green=green, blue=blue, name=name, hex=hex)
r_start, g_start, b_start = blinkstick._remap_rgb_value_reverse(self.get_color(channel, 0), self.max_rgb_value)
if r_start > 255 or g_start > 255 or b_start > 255:
r_start = 0
g_start = 0
b_start = 0
gradient = []
steps += 1
for n in range(1, steps):
d = 1.0 * n / steps
r = (r_start * (1 - d)) + (r_end * d)
g = (g_start * (1 - d)) + (g_end * d)
b = (b_start * (1 - d)) + (b_end * d)
gradient.append((r, g, b))
ms_delay = float(duration) / float(1000 * steps)
self.set_color_all(channel=channel, red=r_start, green=g_start, blue=b_start)
self.send_data_all()
for grad in gradient:
grad_r, grad_g, grad_b = grad
self.set_color_all(channel=channel, red=grad_r, green=grad_g, blue=grad_b)
self.send_data_all()
time.sleep(ms_delay)
self.set_color_all(channel=channel, red=r_end, green=g_end, blue=b_end)
self.send_data_all()
def run(self):
self.send_data_all()
try:
while True:
self.morph_all(0, name="red")
self.morph_all(0, name="black")
time.sleep(0.25)
except KeyboardInterrupt:
self.off()
return
# Change the number of LEDs for r_led_count
main = Main(r_led_count=8, max_rgb_value=128)
if main.connect():
main.run()
else:
print "No BlinkSticks found"