Skip to content

Commit

Permalink
Merge pull request #75 from chaddcw/fix_max_rgb_value_with_blink
Browse files Browse the repository at this point in the history
fix intensity scaling in blink, pulse, and morph
  • Loading branch information
arvydas authored May 4, 2023
2 parents be0164c + b117e3d commit 8140b9f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions blinkstick/blinkstick.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,11 +727,9 @@ def pulse(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None,
@type steps: int
@param steps: Number of gradient steps
"""
r, g, b = self._determine_rgb(red=red, green=green, blue=blue, name=name, hex=hex)

self.turn_off()
for x in range(repeats):
self.morph(channel=channel, index=index, red=r, green=g, blue=b, duration=duration, steps=steps)
self.morph(channel=channel, index=index, red=red, green=green, blue=blue, name=name, hex=hex, duration=duration, steps=steps)
self.morph(channel=channel, index=index, red=0, green=0, blue=0, duration=duration, steps=steps)

def blink(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None, repeats=1, delay=500):
Expand All @@ -753,12 +751,11 @@ def blink(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None,
@type delay: int
@param delay: time in milliseconds to light LED for, and also between blinks
"""
r, g, b = self._determine_rgb(red=red, green=green, blue=blue, name=name, hex=hex)
ms_delay = float(delay) / float(1000)
for x in range(repeats):
if x:
time.sleep(ms_delay)
self.set_color(channel=channel, index=index, red=r, green=g, blue=b)
self.set_color(channel=channel, index=index, red=red, green=green, blue=blue, name=name, hex=hex)
time.sleep(ms_delay)
self.set_color(channel=channel, index=index)

Expand All @@ -783,6 +780,8 @@ def morph(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None,
"""

r_end, g_end, b_end = self._determine_rgb(red=red, green=green, blue=blue, name=name, hex=hex)
# descale the above values
r_end, g_end, b_end = _remap_rgb_value_reverse([r_end, g_end, b_end], self.max_rgb_value)

r_start, g_start, b_start = _remap_rgb_value_reverse(self._get_color_rgb(index), self.max_rgb_value)

Expand Down

0 comments on commit 8140b9f

Please sign in to comment.