-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLCD.py
137 lines (117 loc) · 4.57 KB
/
LCD.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
from hardware_modules.PCF8574 import PCF8574_GPIO
from hardware_modules.Adafruit_LCD1602 import Adafruit_CharLCD
from time import sleep, strftime
from datetime import datetime
PCF8574_address = 0x27 # I2C address of the PCF8574 chip.
PCF8574A_address = 0x3F # I2C address of the PCF8574A chip.
class LCD():
def __init__(self):
# Create PCF8574 GPIO adapter.
try:
self.mcp = PCF8574_GPIO(PCF8574_address)
except:
try:
self.mcp = PCF8574_GPIO(PCF8574A_address)
except:
print ('I2C Address Error !')
exit(1)
self.mcp.output(3,1) # turn on LCD backlight
self.isOn = True # LCD will be on unless you call lightOff()
self.lcd = Adafruit_CharLCD(pin_rs=0, pin_e=2, pins_db=[4,5,6,7], GPIO=self.mcp)
self.lcd.begin(16,2) # set number of LCD lines and columns
self.isLoop = True # control the flow of the program
def getLcdStatus(self):
return self.isOn
def get_time_now(self): # get system time
return datetime.now().strftime(' %H:%M:%S')
def setLoop(self, isLoop):
self.isLoop = isLoop
def getLoop(self):
return self.isLoop
def busy(self):
self.lcd.clear()
while(self.isLoop):
self.lcd.setCursor(0,0) # set cursor position
self.lcd.message(" BUSY \n")
self.lcd.message( self.get_time_now() ) # display the time
sleep(1)
def dnd(self):
self.lcd.clear()
while(self.isLoop):
self.lcd.setCursor(0,0) # set cursor position
self.lcd.message(" DO NOT DISTURB\n")
self.lcd.message( self.get_time_now() ) # display the time
sleep(1)
def brb(self):
self.lcd.clear()
while(self.isLoop):
self.lcd.setCursor(0,0) # set cursor position
self.lcd.message(" BE RIGHT BACK\n")
self.lcd.message( self.get_time_now() ) # display the time
sleep(1)
def away(self):
self.lcd.clear()
while(self.isLoop):
self.lcd.setCursor(0,0) # set cursor position
self.lcd.message(" AWAY \n")
self.lcd.message( self.get_time_now() ) # display the time
sleep(1)
def available(self):
self.lcd.clear()
while(self.isLoop):
self.lcd.setCursor(0,0) # set cursor position
self.lcd.message(" AVAILABLE \n")
self.lcd.message( self.get_time_now() ) # display the time
sleep(1)
def presenting(self):
self.lcd.clear()
while(self.isLoop):
self.lcd.setCursor(0,0) # set cursor position
self.lcd.message(" PRESENTING \n")
self.lcd.message( self.get_time_now() ) # display the time
sleep(1)
self.lcd.setCursor(0,0) # set cursor position
self.lcd.message(" \n")
sleep(1)
def inAcall(self):
self.lcd.clear()
while(self.isLoop):
self.lcd.setCursor(0,0) # set cursor position
self.lcd.message(" IN A CALL \n")
self.lcd.message( self.get_time_now() ) # display the time
sleep(1)
self.lcd.setCursor(0,0) # set cursor position
self.lcd.message(" \n")
sleep(1)
def offline(self):
self.lcd.clear()
while(self.isLoop):
self.lcd.setCursor(0,0) # set cursor position
self.lcd.message(" OFFLINE \n")
self.lcd.message( self.get_time_now() ) # display the time
sleep(1)
def msg(self, otherMessage, clockOn=True):
self.lcd.clear()
while(self.isLoop):
self.lcd.setCursor(0,0)
if len(otherMessage) > 15:
self.lcd.message(otherMessage[:15] + '\n')
elif len(otherMessage) < 10:
self.lcd.message(" " + otherMessage + ' \n')
else:
self.lcd.message(otherMessage + '\n')
if clockOn:
self.lcd.message( self.get_time_now() ) # display the time
else:
self.lcd.message(" \n")
sleep(1)
def destroy(self):
self.setLoop = False
self.lcd.clear()
self.mcp.output(3,0) # turn off LCD backlight
self.isOn = False
def lightOn(self):
self.mcp.output(3,1) # turn on LCD backlight
self.isOn = True
self.setLoop = True