-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
94 lines (74 loc) · 1.77 KB
/
main.py
File metadata and controls
94 lines (74 loc) · 1.77 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from gpiozero import OutputDevice
from time import sleep
LCD_RS=OutputDevice(25)
LCD_E=OutputDevice(24)
LCD_D4=OutputDevice(23)
LCD_D5=OutputDevice(18)
LCD_D6=OutputDevice(15)
LCD_D7=OutputDevice(14)
LCD_WIDTH=16
LCD_CHR=True
LCD_CMD=False
LCD_LINE_1=0x80
LCD_LINE_2=0xC0
E_PULSE=0.0005
E_DELAY=0.0005
def lcd_init():
lcd_byte(0x33,LCD_CMD)
lcd_byte(0x32,LCD_CMD)
lcd_byte(0x28,LCD_CMD)
lcd_byte(0x0C,LCD_CMD)
lcd_byte(0x06,LCD_CMD)
lcd_byte(0x01,LCD_CMD)
sleep(E_DELAY)
def lcd_byte(bits,mode):
LCD_RS.value = mode
LCD_D4.off()
LCD_D5.off()
LCD_D6.off()
LCD_D7.off()
if bits & 0x10:
LCD_D4.on()
if bits & 0x20:
LCD_D5.on()
if bits & 0x40:
LCD_D6.on()
if bits & 0x80:
LCD_D7.on()
lcd_toggle_enable()
LCD_D4.off()
LCD_D5.off()
LCD_D6.off()
LCD_D7.off()
if bits & 0x01:
LCD_D4.on()
if bits & 0x02:
LCD_D5.on()
if bits & 0x04:
LCD_D6.on()
if bits & 0x08:
LCD_D7.on()
lcd_toggle_enable()
def lcd_toggle_enable():
sleep(E_DELAY)
LCD_E.on()
sleep(E_PULSE)
LCD_E.off()
sleep(E_DELAY)
def lcd_string(message,line):
message = message.ljust(LCD_WIDTH," ")
lcd_byte(line,LCD_CMD)
for i in range(LCD_WIDTH):
lcd_byte(ord(message[i]),LCD_CHR)
def read_file(filepath):
with open(filepath,'r') as file:
content = file.read()
return content.split(",")
if __name__=='__main__':
lcd_init()
c = read_file("./names.txt")
while True:
for i in range(len(c)):
lcd_string(c[i].split(" ")[0],LCD_LINE_1)
lcd_string(c[i].split(" ")[1]+" "+c[i].split(" ")[2],LCD_LINE_2)
sleep(3)