forked from the-raspberry-pi-guy/lcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.py
66 lines (55 loc) · 1.52 KB
/
display.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
import lcddriver
class display:
def __init__(self, chars, lines):
self.chars = chars
self.lines = lines
self.display = lcddriver.lcd()
def print_right(self, string, line=1):
if(isinstance(string, list)):
for s in string:
space = ''
offset = self.chars - len(s)
if(offset < 0):
offset = 0
for i in range(0, offset):
space += ' '
print("Printing: "+space + s)
self.display.lcd_display_string(space + s, line)
line += 1
else:
space = ''
offset = self.chars - len(string)
if(offset < 0):
offset = 0
for i in range(0, offset):
space += ' '
print("Printing: "+space + string)
self.display.lcd_display_string(space + string, line)
def print_center(self, string, line=1):
if(isinstance(string, list)):
for s in string:
space = ''
offset = int(self.chars / 2) - int(len(s) / 2)
for i in range(0, offset):
space += ' '
print("Printing: "+space + s)
self.display.lcd_display_string(space + s, line)
line += 1
else:
space = ''
offset = int(self.chars / 2) - int(len(string) / 2)
for i in range(0, offset):
space += ' '
print("Printing: "+space + string)
self.display.lcd_display_string(space + string, line)
def print_left(self, string, line=1):
if(isinstance(string, list)):
for s in string:
print("Printing: "+ s)
self.display.lcd_display_string(s, line)
line += 1
else:
print("Printing: "+ string)
self.display.lcd_display_string(string, line)
def lcd_clear():
self.display.lcd_clear()