Skip to content
Snippets Groups Projects
Verified Commit 50eeecd9 authored by rahix's avatar rahix
Browse files

style(ledfx): Reformat docs and comments


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent ab8ee07f
No related branches found
No related tags found
No related merge requests found
import leds, utime, math import leds
import math
import utime
def col_cor(colors, brightness=1, gamma=1): def col_cor(colors, brightness=1, gamma=1):
...@@ -12,13 +14,16 @@ def col_cor(colors, brightness=1, gamma=1): ...@@ -12,13 +14,16 @@ def col_cor(colors, brightness=1, gamma=1):
def halo(colors): def halo(colors):
""" """
sets the four bottom/side LEDs to colors corresponding to the color spectrum on the outermost of the top 11 LEDs Set the four bottom/side LEDs to colors corresponding to the color spectrum
on the outermost of the top 11 LEDs.
""" """
used_leds = len(colors) used_leds = len(colors)
#add additional RGB-Color-lists to the colors-list to fill up the top LEDs with emptiness
# add additional RGB-Color-lists to the colors-list to fill up the top LEDs with emptiness
colors += [[0, 0, 0]] * (11 - used_leds) colors += [[0, 0, 0]] * (11 - used_leds)
#add four additional colors. the last one, the first one twice, the last one.
# add four additional colors. the last one, the first one twice, the last one.
colors += [colors[used_leds - 1]] + [colors[0]] * 2 + [colors[used_leds - 1]] colors += [colors[used_leds - 1]] + [colors[0]] * 2 + [colors[used_leds - 1]]
return colors return colors
...@@ -30,51 +35,61 @@ def kitt( ...@@ -30,51 +35,61 @@ def kitt(
minimum=0.3, minimum=0.3,
rgb=[255, 0, 0], rgb=[255, 0, 0],
spectrum=[], spectrum=[],
halo=False, halo=False,
): ):
""" """
LED Animation. Knight rider-Style. LED Animation. Knight rider-Style.
:param cycles: amount of cycles for the animation
:param delay: time in microseconds until the animation moves on. (we could also call it framerate) :param int cycles: Amount of cycles for the animation
:param power: the shape of your brightness curve. bigger values make a steeper curve, smaller values make the curve wider. :param int delay: Time in microseconds until the animation moves on (Inverse of Framerate).
:param minimum: the minimal brightness :param int power: Shape of your brightness curve. Bigger values make a
:param rgb: if you don't enter a spectrum this is the color we'll use steeper curve, smaller values make the curve wider.
:param specttrum: a color spectrum consisting of up to 11 RGB-Value-Lists (e.g. [[255,255,255], [0,0,0], [255,255,255] and so on] - ). if you use less, the animation will be less wide. :param float minimum: Minimal brightness.
:param [r,g,b] rgb: If you don't enter a spectrum this is the color used.
:param list spectrum: A color spectrum consisting of up to 11 RGB-Value-Lists
(e.g. ``[[255,255,255], [0,0,0], [255,255,255], ...]`` ). If you use
less, the animation will be less wide.
:param func halo: Halo function. See :py:func:`ledfx.halo`.
""" """
# create a basic table of values for a smooth increment of the LED brightness (if you don't understand this, don't worry, i don't either. just paste it into the python shell and see the output). Basically creates a negative cosinus curve. # create a basic table of values for a smooth increment of the LED
# brightness (if you don't understand this, don't worry, i don't either.
# just paste it into the python shell and see the output). Basically
# creates a negative cosinus curve.
kitt_table = [((-math.cos(math.pi * (x / 10.0))) + 1) / 2.0 for x in range(21)] kitt_table = [((-math.cos(math.pi * (x / 10.0))) + 1) / 2.0 for x in range(21)]
#adjust the values to start with a minimum brightness and the width of the curve to the given power.
# adjust the values to start with a minimum brightness and the width of the
# curve to the given power.
kitt_table = [math.pow(x, power) * (1 - minimum) + minimum for x in kitt_table] kitt_table = [math.pow(x, power) * (1 - minimum) + minimum for x in kitt_table]
#for the amount of specified cycles # for the amount of specified cycles
for i in range(cycles): for i in range(cycles):
#repeat every 20 steps # repeat every 20 steps
j = i % 20 j = i % 20
#and go backwards after 10 steps # and go backwards after 10 steps
if j > 10: if j > 10:
j = 20 - j j = 20 - j
#if a color spectrum wasn't given
if spectrum == []: if spectrum == []:
#set the amount of LEDs used to 11, because we're using the full width
used_leds = 11 used_leds = 11
#set the color values to the LEDs by multiplying the given color value with the corresponding brightness value in the kitt table
# set the color values to the LEDs by multiplying the given color
# value with the corresponding brightness value in the kitt table
output = [[int(x * y) for y in rgb] for x in kitt_table[j : (j + used_leds)]] output = [[int(x * y) for y in rgb] for x in kitt_table[j : (j + used_leds)]]
else: else:
#use the amount of leds specified in the spectrum
used_leds = len(spectrum) used_leds = len(spectrum)
#multiply the color values in the corresponding spectrum tuple with the brightness value in the kitt table
# multiply the color values in the corresponding spectrum tuple
# with the brightness value in the kitt table
output = [ output = [
[int(y * kitt_table[j + x]) for y in spectrum[x]] [int(y * kitt_table[j + x]) for y in spectrum[x]]
for x in range(used_leds) for x in range(used_leds)
] ]
#if a halo is True, also use the four bottom LEDs
if halo: if halo:
halo(output) halo(output)
#set the LEDs to the output defined above
leds.set_all(output) leds.set_all(output)
#sleep for the amount of milliseconds specified in delay
utime.sleep_ms(delay) utime.sleep_ms(delay)
#Switch off all LEDs.
leds.clear() leds.clear()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment