Last active
January 17, 2023 18:25
-
-
Save todbot/8c31150b373c8d2eb5d6c5f8fcafca12 to your computer and use it in GitHub Desktop.
Trinkey Dance Party : fun pulsing colors for NeoTrinkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Trinkey dance party | |
# 2021 @todbot | |
import time | |
import board | |
import neopixel | |
import random | |
leds = neopixel.NeoPixel(board.NEOPIXEL, 4, brightness=0.3, auto_write=False) | |
bpm = 130 | |
ms_per_beat = int(60e3 / bpm / 16) | |
i=0 | |
while True: | |
leds[0:] = [[max(i-8,0) for i in l] for l in leds] # fadeToBlackBy(8) | |
leds.show() | |
i = (i+1) % ms_per_beat | |
if i==0: | |
leds[0:] = [int(random.random() * 2**24) for l in leds] # each LED gets new random color | |
time.sleep(0.01) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome, let me know if you have any other questions.
If you're just getting started, the above is using a Python trick called "list comprehensions" to do things in one line.
So for instance this line:
is the same as: