forked from rdagger/micropython-ssd1351
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_color_palette.py
60 lines (50 loc) · 1.28 KB
/
demo_color_palette.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""SSD1351 demo (color palette)."""
from time import sleep
from ssd1351 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 14500000 seems about the max
spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23))
display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16))
c = 0
for x in range(0, 128, 16):
for y in range(0, 128, 16):
color = color565(*hsv_to_rgb(c / 64, 1, 1))
display.fill_circle(x + 7, y + 7, 7, color)
c += 1
sleep(9)
display.cleanup()
test()