Skip to content
Snippets Groups Projects
Select Git revision
  • b64e91b8f1746dfaf422b026b744824861e28cf9
  • master default protected
  • backslash
  • nickname-match-configs
  • genofire/leds_rgb_get_state
  • genofire/rockets-state
  • genofire/ble-follow-py
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • genofire/haule-ble-fs-deactive
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • ios-workarounds
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • koalo/wip/i2c-for-python
  • 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
34 results

genapi.py

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    ledfx.py 1.23 KiB
    import leds, utime, math
    
    
    def col_cor(colors, brightness=1, gamma=1):
        return [
            [int(255 * brightness * math.pow((y / 255.0), gamma)) for y in x]
            for x in colors
        ]
    
    
    def halo(colors):
        used_leds = len(colors)
        colors += [[0, 0, 0]] * (11 - used_leds)
        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.
        """
        kitt_table = [((-math.cos(math.pi * (x / 10.0))) + 1) / 2.0 for x in range(21)]
        kitt_table = [math.pow(x, power) * (1 - minimum) + minimum for x in kitt_table]
    
        for i in range(cycles):
            j = i % 20
            if j > 10:
                j = 20 - j
            if spectrum == []:
                used_leds = 11
                output = [[int(x * y) for y in rgb] for x in kitt_table[j : (j + 11)]]
            else:
                used_leds = len(spectrum)
                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()