-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.py
51 lines (47 loc) · 1.5 KB
/
driver.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
from machine import Pin, I2C
from neopixel import NeoPixel
class Light:
buf = []
def __init__(self):
for i in range(10):
row = []
for j in range(12):
row.append((0,0,0))
self.buf.append(row)
self.light = NeoPixel(Pin(13, Pin.OUT), 120)
def update(self):
for i in range(10):
if i % 2 == 0:
for j in range(12):
reverse_col = 11 - j
self.light[i*12 + reverse_col] = self.buf[i][j]
else:
for j in range(12):
self.light[i*12 + j] = self.buf[i][j]
self.light.write()
def show(self, img):
for i in range(10):
for j in range(12):
self.buf[i][j] = img[i][j]
self.update()
def show_re(self, img):
for i in range(10):
for j in range(12):
self.buf[9-i][j] = img[j][i]
self.update()
class Touch:
def __init__(self):
self.touch = I2C(1, freq=100000, timeout=50)
def is_touch(self, val):
try:
if 0 <= val and val < 8:
buf = self.touch.readfrom_mem(0x50, 8, 1)
if buf[0] & (1 << val):
return True
if 8 <= val and val < 12:
buf = self.touch.readfrom_mem(0x50, 9, 1)
if buf[0] & (1 << (val-8)):
return True
except Exception:
pass
return False