-
Notifications
You must be signed in to change notification settings - Fork 1
/
microcontroller.py
executable file
·74 lines (60 loc) · 2.07 KB
/
microcontroller.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
70
71
72
73
74
import pyb
pins = pyb.Pin.board
class Microcontroller:
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super().__new__(cls, *args, **kwargs)
return cls._instance
def __init__(self, smallBoard=False):
self.R1 = None
self.R2 = None
self.B2 = None
self.G1 = None
self.G2 = None
self.A = None
self.B = None
self.C = None
self.D = None
self.OE = None
self.LAT = None
self.CLK = None
self.smallBoard = smallBoard
self.set_RGB_pins()
self.set_row_select_pins()
self.set_control_pins()
def set_RGB_pins(self, R1, R2, B1, B2, G1, G2):
raise NotImplementedError('Need to implement set_RGB_data method.')
def set_row_select_pins(self, A, B, C, D):
raise NotImplementedError('Need to implement set_row_select method.')
def set_control_pins(self, LAT, OE):
raise NotImplementedError('Need to implement set_control_pins method.')
def latch(self):
self.LAT.value(0)
pyb.udelay(500)
self.LAT.value(1)
class Pyboard(Microcontroller):
def set_RGB_pins(
self,
R1=pins.Y1,
R2=pins.Y2,
B1=pins.Y3,
B2=pins.Y4,
G1=pins.Y5,
G2=pins.Y6):
self.R1 = pyb.Pin(R1, pyb.Pin.OUT)
self.R2 = pyb.Pin(R2, pyb.Pin.OUT)
self.B1 = pyb.Pin(B1, pyb.Pin.OUT)
self.B2 = pyb.Pin(B2, pyb.Pin.OUT)
self.G1 = pyb.Pin(G1, pyb.Pin.OUT)
self.G2 = pyb.Pin(G2, pyb.Pin.OUT)
def set_row_select_pins(self, A=pins.Y7, B=pins.Y8, C=pins.X9, D=pins.X10):
self.A = pyb.Pin(A, pyb.Pin.OUT)
self.B = pyb.Pin(B, pyb.Pin.OUT)
self.C = pyb.Pin(C, pyb.Pin.OUT)
self.D = pyb.Pin(D, pyb.Pin.OUT)
def set_control_pins(self, LAT=pins.X11, OE=pins.X12, CLK=pins.X1):
self.LAT = pyb.Pin(LAT, pyb.Pin.OUT)
self.LAT.value(1)
self.OE = pyb.Pin(OE, pyb.Pin.OUT)
self.CLK = pyb.Pin(CLK, pyb.Pin.OUT)