sync
This commit is contained in:
1
rainbow_buttons/README.md
Normal file
1
rainbow_buttons/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Source: https://gist.github.com/paulwinex/a65f0a36485ae1dea3de4a82f647949a
|
||||
71
rainbow_buttons/main.py
Normal file
71
rainbow_buttons/main.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import time
|
||||
from machine import Pin, SPI
|
||||
import st7789 as st7789
|
||||
from random import randrange, choice
|
||||
|
||||
|
||||
def hsv_to_rgb(h, s, v):
|
||||
if s == 0.0:
|
||||
return v, v, v
|
||||
i = int(h * 6.0) # XXX assume int() truncates!
|
||||
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 int(v * 255), int(t * 255), int(p * 255)
|
||||
if i == 1:
|
||||
return int(q * 255), int(v * 255), int(p * 255)
|
||||
if i == 2:
|
||||
return int(p * 255), int(v * 255), int(t * 255)
|
||||
if i == 3:
|
||||
return int(p * 255), int(q * 255), int(v * 255)
|
||||
if i == 4:
|
||||
return int(t * 255), int(p * 255), int(v * 255)
|
||||
if i == 5:
|
||||
return int(v * 255), int(p * 255), int(q * 255)
|
||||
# Cannot get here
|
||||
|
||||
|
||||
def rainbow():
|
||||
print('RAINBOW')
|
||||
for i in range(240):
|
||||
color = st7789.color565(*hsv_to_rgb(i / 240, 1.0, 1.0))
|
||||
tft.hline(0, i, 135, color)
|
||||
|
||||
|
||||
def fill():
|
||||
print('FILL')
|
||||
tft.fill_rect(0, 0, 135, 240, st7789.color565(
|
||||
randrange(0, 255), randrange(0, 255), randrange(0, 255)
|
||||
))
|
||||
|
||||
|
||||
def main():
|
||||
p1 = Pin(0, Pin.IN)
|
||||
p2 = Pin(35, Pin.IN)
|
||||
|
||||
time.sleep(0.5)
|
||||
tft = st7789.ST7789(
|
||||
SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
|
||||
135,
|
||||
240,
|
||||
reset=Pin(23, Pin.OUT),
|
||||
cs=Pin(5, Pin.OUT),
|
||||
dc=Pin(16, Pin.OUT),
|
||||
backlight=Pin(4, Pin.OUT),
|
||||
rotation=0
|
||||
)
|
||||
tft.init()
|
||||
|
||||
time.sleep(0.5)
|
||||
fill()
|
||||
while True:
|
||||
if not p1.value():
|
||||
rainbow()
|
||||
elif not p2.value():
|
||||
fill()
|
||||
time.sleep(0.1)
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user