Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit 5dd7a14

Browse files
committed
Create LCD_ DataTable.py
1 parent 39a222a commit 5dd7a14

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/usr/bin/python
2+
#----------------------------------------------------------------
3+
# Author: Chris Crumpacker
4+
# Date: May 2013
5+
#
6+
# Testing a data table on an 20x4 LCD,
7+
# using a RaspberyPi and an MCP23017 I2C port expander
8+
#
9+
# Using Adafruit_CharLCD code with the I2C and MCP230xx code as well
10+
#----------------------------------------------------------------
11+
12+
from time import sleep
13+
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
14+
from EoL_HandlingAnd4LineSupport import LCD_EoL_Handling
15+
16+
class LCD_DataTable(Adafruit_CharLCDPlate):
17+
# Limited to 4 characters,
18+
# position is left or right,
19+
# line is 1-4
20+
def labelHalf(self, text, position, line):
21+
if position == "left":
22+
lcd.setCursor(0,line)
23+
eol.message(" :")
24+
lcd.setCursor(0,line)
25+
eol.message(text[0:4]+':')
26+
elif position == "right":
27+
lcd.setCursor(10,line)
28+
eol.message(" :")
29+
lcd.setCursor(10,line)
30+
eol.message('|'+text[0:4]+':')
31+
32+
# Limited to 4 characters,
33+
# position is left or right,
34+
# line is 1-4
35+
def valueHalf(self, text, position, line):
36+
if position == "left":
37+
lcd.setCursor(5,line)
38+
eol.message(" ")
39+
lcd.setCursor(5,line)
40+
eol.message(text[0:4])
41+
elif position == "right":
42+
lcd.setCursor(16,line)
43+
eol.message(" ")
44+
lcd.setCursor(16,line)
45+
eol.message(text[0:4])
46+
47+
# Writes up to a 9 character lable and value to a full line
48+
def wholeLine(self, label, value, line):
49+
self.clearLine(line)
50+
lcd.setCursor(0,line)
51+
eol.message(label[0:10] + ': ')
52+
lcd.setCursor(11,line)
53+
eol.message(value[0:10])
54+
55+
#Clears an entire line
56+
def clearLine(self, line):
57+
lcd.setCursor(0,line)
58+
eol.message(" " * columns)
59+
60+
# Clears just a half data set, label and value
61+
def clearDataSet(self, position,line):
62+
if position == "left":
63+
lcd.setCursor(0,line)
64+
eol.message(" " * 10)
65+
elif position == "right":
66+
lcd.setCursor(10,line)
67+
eol.message(" " * 10)
68+
69+
# Clears just the value portion for a half data set
70+
def clearHalfValue(self, position,line):
71+
if position == "left":
72+
lcd.setCursor(5,line)
73+
eol.message(" ")
74+
elif position == "right":
75+
lcd.setCursor(16,line)
76+
eol.message(" ")
77+
78+
#----------------------------------------------------------------
79+
# Main program, just trowing bogus data "against the wall"
80+
#----------------------------------------------------------------
81+
if __name__ == '__main__':
82+
83+
#lcd size reference
84+
columns = 20
85+
rows = 4
86+
87+
eol = LCD_EoL_Handling()
88+
lcd = Adafruit_CharLCDPlate()
89+
dt = LCD_DataTable()
90+
91+
lcd.begin(columns, rows)
92+
lcd.backlight(lcd.ON)
93+
lcd.clear()
94+
95+
lcd.message("20x4 Table Testing")
96+
sleep(2)
97+
98+
#Filling the table with bogus info
99+
lcd.clear()
100+
dt.labelHalf("Temp","left",0)
101+
dt.labelHalf("Mode","right",0)
102+
dt.labelHalf("Targ","left",1)
103+
dt.labelHalf("Fan","right",1)
104+
dt.valueHalf("Cool","right",0)
105+
dt.valueHalf("75.5","left",0)
106+
dt.valueHalf("Auto","right",1)
107+
dt.valueHalf("74.0","left",1)
108+
dt.wholeLine("Tempurature", "Too Hot",2)
109+
110+
#Start testing updating and clearing parts
111+
sleep(5)
112+
dt.clearLine(0)
113+
sleep(2)
114+
dt.labelHalf("Temp","left",0)
115+
dt.valueHalf("76.0","left",0)
116+
sleep(2)
117+
dt.valueHalf("74.75","left",0)
118+
sleep(2)
119+
dt.labelHalf("Mode","right",0)
120+
dt.valueHalf("Both","right",0)
121+
sleep(2)
122+
dt.valueHalf("On","right",0)
123+
sleep(2)
124+
dt.clearDataSet("left",0)
125+
sleep(2)
126+
dt.labelHalf("Tempurature","left",0)
127+
dt.valueHalf("85","left",0)
128+
sleep(5)

0 commit comments

Comments
 (0)