You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3 KiB
Python

5 years ago
"""ILI9341 demo (color palette)."""
from time import sleep
from ili9341 import Display, color565
from machine import Pin, SPI
def hsv_to_rgb(h, s, v):
"""
Convert HSV to RGB (based on colorsys.py).
Args:
h (float): Hue 0 to 1.
s (float): Saturation 0 to 1.
v (float): Value 0 to 1 (Brightness).
"""
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
v = int(v * 255)
t = int(t * 255)
p = int(p * 255)
q = int(q * 255)
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
def test():
"""Test code."""
# Baud rate of 40000000 seems about the max
spi = SPI(2, baudrate=40000000, sck=Pin(18), mosi=Pin(23))
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
c = 0
for x in range(0, 240, 20):
for y in range(0, 320, 20):
color = color565(*hsv_to_rgb(c / 192, 1, 1))
display.fill_circle(x + 9, y + 9, 9, color)
c += 1
sleep(9)
display.cleanup()
test()