Skip to content

Commit 4ffe6de

Browse files
authored
Update character_lcd.py
1 parent 3d4340c commit 4ffe6de

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

adafruit_character_lcd/character_lcd.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def __init__(self, rs, en, d4, d5, d6, d7, columns, lines
173173
# itialize to 0,0
174174
self.row = 0
175175
self.column = 0
176+
self._column_align = False
176177
# pylint: enable-msg=too-many-arguments
177178

178179
def home(self):
@@ -201,6 +202,17 @@ def clear(self):
201202
"""
202203
self._write8(_LCD_CLEARDISPLAY)
203204
time.sleep(0.003)
205+
206+
@property
207+
def column_align(self):
208+
"""If True, message text after '\n' starts directly below start of first
209+
character in message. If False, text after '\n' starts at column zero.
210+
"""
211+
return self._column_align
212+
213+
@column_align.setter
214+
def column_align(self, enable):
215+
self._column_align = enable
204216

205217
@property
206218
def cursor(self):
@@ -234,8 +246,9 @@ def cursor(self, show):
234246
self._write8(_LCD_DISPLAYCONTROL | self.displaycontrol)
235247

236248
def cursor_position(self, column, row):
237-
"""Move the cursor to position ``column``, ``row``
238-
249+
"""Move the cursor to position ``column``, ``row`` for the next
250+
message only. Displaying a message resets the cursor position to (0, 0).
251+
239252
:param column: column location
240253
:param row: row location
241254
"""
@@ -369,6 +382,13 @@ def message(self, message):
369382
# which case start on the opposite side of the display if cursor_position
370383
# is (0,0) or not set. Start second line at same column as first line when
371384
# cursor_position is set
385+
if self.displaymode & _LCD_ENTRYLEFT > 0:
386+
col = self.column * self._column_align
387+
else:
388+
if self._column_align:
389+
col = self.column
390+
else:
391+
col = self.columns - 1
372392
self.cursor_position(col, line)
373393
# Write string to display
374394
else:

0 commit comments

Comments
 (0)