Skip to content

Instantly share code, notes, and snippets.

@ah01
Created September 18, 2021 20:38
Show Gist options
  • Save ah01/cccfe89f9ff56eddf24479582c4575dd to your computer and use it in GitHub Desktop.
Save ah01/cccfe89f9ff56eddf24479582c4575dd to your computer and use it in GitHub Desktop.
Matrix effect for Pico Scroll Pack board
# Simple Matrix style effect for Pico Scroll Pack board from Pimoroni and MicroPython on Raspbery Pi Pico
# see: https://twitter.com/horcicaa/status/1439327623843307523
# doc: https://shop.pimoroni.com/products/pico-scroll-pack
# https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/modules/pico_scroll
import time
import random
import picoscroll as scroll
# --- config ---
# Initial brightness for new pixel
brightness = 30
# How much pixel should fade on next line
fade = 0.8
# Probability of new pixel ( 1 : n )
probability = 5
# --------------
scroll.init()
W = scroll.get_width()
H = scroll.get_height()
buffer = bytearray(0 for j in range(W*H))
# Calc. index of pixel in buffer by x and y position
def n(x, y):
return y * W + x
while True:
# Shift rows one row down
for x in range(W-1, 0, -1):
for y in range(0, H):
buffer[n(x,y)] = buffer[n(x-1, y)]
# Calculate new row on top
for i in range(0, H):
buffer[n(0, i)] = int(buffer[n(1, i)] * fade)
# Add point
if random.randint(0, probability - 1) == 0:
buffer[n(0, random.randint(0, H-1))] = brightness
# Refresh
scroll.set_pixels(buffer)
scroll.update()
time.sleep(0.04)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment