Skip to content

Instantly share code, notes, and snippets.

@todbot
Created May 7, 2024 00:13
Show Gist options
  • Save todbot/9e4aad775915e78651c6fdd386fce402 to your computer and use it in GitHub Desktop.
Save todbot/9e4aad775915e78651c6fdd386fce402 to your computer and use it in GitHub Desktop.
I'm always blocking for midi
# waiting_for_midi_code.py -- I'm always blocking for midi
# 6 May 2024 - @todbot
# works on PicoDVI RP2040 Feather / DVI Cowbell / etc.
import time, math, random
import board
import displayio
import bitmaptools
from adafruit_display_text import bitmap_label as label
num_colors = 16 # how many colors for our bitmap, can't be over 16 for DVI
circle_detail = 48
display = board.DISPLAY
display.auto_refresh = False
display.root_group = displayio.Group()
dw,dh = display.width, display.height
cx,cy = dw//2, dh//2
# create a palette of colors to choose from, this one is shades of neon green
import rainbowio
pal = displayio.Palette(num_colors)
pal[0] = 0x000000
for i in range(1,len(pal)):
pal[i] = rainbowio.colorwheel( 180 + i / num_colors * 55 )
bitmap = displayio.Bitmap(dw, dh, num_colors)
tile_grid = displayio.TileGrid(bitmap, pixel_shader=pal)
display.root_group.append(tile_grid)
import terminalio
text = label.Label(font=terminalio.FONT, scale=3, x=15, y=cy, color=0x000000, text="waiting for MIDI")
display.root_group.append(text)
print("cx,cy:", cx,cy)
last_time = 0
while True:
if time.monotonic() - last_time > 0.05:
last_time = time.monotonic()
r = random.randint(10,30) # 20
x = random.randint(r+1, dw-r-1)
y = random.randint(r+1, dh-r-1)
c = random.randint(0,num_colors-1)
# draw outer circle
bitmaptools.draw_circle(bitmap, x,y,r,c)
# draw inner "spokes"
for i in range(circle_detail):
angle = math.pi*2 * i / circle_detail
vx = x + r * math.cos(angle)
vy = y + r * math.sin(angle)
bitmaptools.draw_line(bitmap, int(vx), int(vy), x, y, c)
display.refresh()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment