"""
"""
import os
import sys
from machine import SPI, Pin
import time
import random
from ST7735 import TFT, TFTColor
# Define pin numbers
DC = 16 #aDC=16
RST = 17 # aReset=17
MOSI = 11 # mosi=11
SCK = 10 # sck=10
CS = 18 # aCS=18
if __name__ == "__main__":
print("====================================")
print(sys.implementation[0], os.uname()[3],
"\nrun on", os.uname()[4])
print("====================================")
# Initialize SPI communication
spi = SPI(1, baudrate=20000000, polarity=0, phase=0,
sck=Pin(SCK), mosi=Pin(MOSI), miso=None
)
# Initialize the ST7735 display
tft = TFT(spi, DC, RST, CS)
tft.initr()
tft.rgb(True) # Enable color
# https://blog.boochow.com/article/micropython-st7735-vertical-scroll.html
tft.setvscroll(17, 17)
tft.fill(TFT.BLACK)
tft.fillrect((0, 0), (128, 16), TFT.PURPLE)
tft.fillrect((0, 144), (128, 16), TFT.CYAN)
tft.fillcircle((64, 80), 64, TFT.YELLOW)
tft.fillcircle((48, 60), 4, TFT.BLACK)
tft.fillcircle((80, 60), 4, TFT.BLACK)
tft.fillrect((32, 100), (64, 2), TFT.BLACK)
for i in range(0, 129):
tft.vscroll(i)
time.sleep_ms(50)
# https://coxxect.blogspot.com/2022/08/micropythonesp32-c3-18-128x160-tft.html
tft.fill(TFT.BLACK)
#Random pixel
for p in range(1000):
x = random.randint(5, tft.size()[0]-10)
y = random.randint(5, tft.size()[1]-10)
c = TFTColor(random.randint(0, 0xFF),
random.randint(0, 0xFF),
random.randint(0, 0xFF))
tft.pixel((x, y), c)
#Random line
for l in range(100):
tft.line((random.randint(5, tft.size()[0]-10),
random.randint(5, tft.size()[1]-10)),
(random.randint(5, tft.size()[0]-10),
random.randint(5, tft.size()[1]-10)),
TFTColor(random.randint(0, 0xFF),
random.randint(0, 0xFF),
random.randint(0, 0xFF)))
#Random circle
for l in range(20):
tft.circle((random.randint(5, tft.size()[0]-10),
random.randint(5, tft.size()[1]-10)),
random.randint(1, 50),
TFTColor(random.randint(0, 0xFF),
random.randint(0, 0xFF),
random.randint(0, 0xFF)))
#Random fillcircle
for l in range(20):
tft.fillcircle((random.randint(5, tft.size()[0]-10),
random.randint(5, tft.size()[1]-10)),
random.randint(1, 50),
TFTColor(random.randint(0, 0xFF),
random.randint(0, 0xFF),
random.randint(0, 0xFF)))
tft.fill(TFT.BLACK)
print("~ bye ~")