Skip to content
Snippets Groups Projects
Select Git revision
  • 9cab153acd3754f40a958a3c55fb4b46fa6dba6e
  • master default protected
  • right_scroll_config
  • ofscreen_lines
  • simple_menu_buttons
  • rahix/meson-micropython
  • schneider/ecg-plot
  • rahix/proper-sleep
  • rahix/panic
  • genofire/ble-follow-py
  • schneider/ble-stability-new-phy-adv
  • schneider/ble-stability
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
36 results

DEV_Config.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    ledfx.py 3.08 KiB
    import leds
    import math
    import utime
    
    
    def col_cor(colors, brightness=1, gamma=1):
        """
        Gamma and  brightness correction for the RGB channels
        """
        return [
            [int(255 * brightness * math.pow((y / 255.0), gamma)) for y in x]
            for x in colors
        ]
    
    
    def halo(colors):
        """
        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)
    
        # add additional RGB-Color-lists to the colors-list to fill up the top LEDs with emptiness
        colors += [[0, 0, 0]] * (11 - used_leds)
    
        # 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]]
        return colors
    
    
    def kitt(
        cycles=100,
        delay=80,
        power=10,
        minimum=0.3,
        rgb=[255, 0, 0],
        spectrum=[],
        halo=False,
    ):
        """
        LED Animation. Knight rider-Style.
    
        :param int cycles: Amount of cycles for the animation
        :param int delay: Time in microseconds until the animation moves on (Inverse of Framerate).
        :param int power: Shape of your brightness curve.  Bigger values make a
           steeper curve, smaller values make the curve wider.
        :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.
        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.
        kitt_table = [math.pow(x, power) * (1 - minimum) + minimum for x in kitt_table]
    
        # for the amount of specified cycles
        for i in range(cycles):
            # repeat every 20 steps
            j = i % 20
            # and go backwards after 10 steps
            if j > 10:
                j = 20 - j
    
            if spectrum == []:
                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
                output = [[int(x * y) for y in rgb] for x in kitt_table[j : (j + used_leds)]]
            else:
                used_leds = len(spectrum)
    
                # multiply the color values in the corresponding spectrum tuple
                # with the brightness value in the kitt table
                output = [
                    [int(y * kitt_table[j + x]) for y in spectrum[x]]
                    for x in range(used_leds)
                ]
    
            if halo:
                halo(output)
    
            leds.set_all(output)
            utime.sleep_ms(delay)
    
        leds.clear()