Created
July 27, 2025 21:12
-
-
Save MichaelBell/41cb55bee3a4463ed62cf0445ec6cc1c to your computer and use it in GitHub Desktop.
TinyQV ledstrip peripheral example
This file contains hidden or 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
| # Demo for peripheral 18 on https://github.com/TinyTapeout/ttsky25a-tinyqv | |
| import machine | |
| import time | |
| # HSV to RGB function for generating rainbows | |
| def hsv_to_rgb(h, s, v): | |
| if s == 0.0: | |
| return v, v, v | |
| i = int(h * 6.0) | |
| f = (h * 6.0) - i | |
| p = v * (1.0 - s) | |
| q = v * (1.0 - s * f) | |
| t = v * (1.0 - s * (1.0 - f)) | |
| i = i % 6 | |
| if i == 0: | |
| return v, t, p | |
| if i == 1: | |
| return q, v, p | |
| if i == 2: | |
| return p, v, t | |
| if i == 3: | |
| return p, q, v | |
| if i == 4: | |
| return t, p, v | |
| if i == 5: | |
| return v, p, q | |
| # Set a colour by writing the peripheral's registers | |
| def set_colour(r, g, b): | |
| machine.mem8[0x800_0421] = g | |
| machine.mem8[0x800_0422] = r | |
| machine.mem8[0x800_0423] = b | |
| # Get output pin 1 and set function to 18 (WS2812 peripheral) | |
| pin = machine.Pin(1, func_sel=18) | |
| for _ in range(10): | |
| for i in range(255): | |
| # Generate a rainbow colour | |
| r,g,b = hsv_to_rgb(i/255,1,1) | |
| # Set it | |
| set_colour(int(r*8), int(g*8), int(b*8)) | |
| # Light some pixels | |
| machine.mem8[0x800_0420] = 0x1f | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment