forked from Hack-a-Day/Vectorscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen.py
74 lines (56 loc) · 2.09 KB
/
screen.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
61
62
63
64
65
66
67
68
69
from machine import Pin, SPI, SoftSPI
import pin_defs
import gc9a01
import gc
import rp2
class Screen():
def __init__(self, softSPI=False):
self.softSPI = softSPI
self.sck = Pin(pin_defs.sck, Pin.OUT)
self.data = Pin(pin_defs.data, Pin.OUT)
self.dc = Pin(pin_defs.dc, Pin.OUT)
self.init()
def deinit(self):
self.spi.deinit()
## this does not appear to de-initialize the DMAs -- the enable bits are still set
del(self.spi)
del(self.tft)
gc.collect()
def init(self):
if self.softSPI:
self.spi = SoftSPI(baudrate=10_000_000, sck=self.sck, mosi=self.data, miso=Pin(pin_defs.throwaway))
else:
self.spi = SPI(0, baudrate=40_000_000, sck=self.sck, mosi=self.data)
self.tft = gc9a01.GC9A01(self.spi, 240, 240,
reset = Pin(pin_defs.reset, Pin.OUT),
cs = Pin(pin_defs.throwaway, Pin.OUT), ## not used, grounded on board
dc = self.dc,
backlight = Pin(pin_defs.throwaway, Pin.OUT), ## not used, always on
rotation = 0)
self.tft.init()
self.tft.fill(gc9a01.color565(10,15,10))
if __name__ == "__main__":
import time
import random
## instantiate and init
s = Screen()
## For everything you can do with the GC9A01 library:
## https://github.com/russhughes/gc9a01_mpy
s.tft.fill(gc9a01.BLUE)
time.sleep_ms(500)
s.tft.fill(gc9a01.YELLOW)
time.sleep_ms(500)
s.tft.fill(gc9a01.BLACK)
phosphor_bright = gc9a01.color565(120, 247, 180)
phosphor_dark = gc9a01.color565(45, 217, 80)
## better graphic demo should go here
for i in range(200):
x1 = random.randint(0, 240)
x2 = random.randint(0, 240)
y1 = random.randint(0, 240)
y2 = random.randint(0, 240)
if i % 2:
s.tft.line(x1, y1, x2, y2, phosphor_bright)
else:
s.tft.line(x1, y1, x2, y2, phosphor_dark)
time.sleep_ms(20)