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) | |
Thanks, this is great!
Much appreciated.
I'm getting started with simple coding and this has been really helpful.
ae.
…On Mon, Jan 16, 2023 at 11:30 PM Tod Kurt ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
How would you write this script so that pushing the buttons increases and
decreases the BPM?
Here's how I would do that today:
Trinkey dance party, now with changable BPM# 16 Jan 2023 - @todbot / Tod Kurt#import time, random, board, neopixel, rainbowio, touchio
leds = neopixel.NeoPixel(board.NEOPIXEL, 4, brightness=0.3, auto_write=False)touch1 = touchio.TouchIn(board.TOUCH1)touch2 = touchio.TouchIn(board.TOUCH2)
bpm = 130i=0while True:
ms_per_beat = int(60e3 / bpm / 16)
leds[0:] = [[max(i-8,0) for i in l] for l in leds] # same as "fadeToBlackBy(8)"
leds.show()
i = (i+1) % ms_per_beat
if i==0: # at the beat, each LED gets new random color
leds[0:] = [rainbowio.colorwheel(random.random()*255) for l in leds]
# touch pads change BPM up or down
if touch1.value:
bpm = bpm - 1
if touch2.value:
bpm = bpm + 1
if touch1.value and touch2.value: # reset BPM if both are touched
bpm = 130
time.sleep(0.01)
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/8c31150b373c8d2eb5d6c5f8fcafca12#gistcomment-4439259>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A5IABKEQIVIZHH5P2XOUOJDWSY4B5BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTAOJSGY3DMMJTU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
--
Andres Esparza
915.740.5178
http://lazymanadventures.wordpress.com/
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:
leds[0:] = [rainbowio.colorwheel(random.random()*255) for l in leds]
is the same as:
for i in range(len(leds)):
leds[i] = rainbowio.colorwheel(random.random()*255)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's how I would do that today: