Skip to content
Prev Previous commit
Next Next commit
Update character_lcd.py
  • Loading branch information
profbrady authored Apr 10, 2019
commit a6eb4efdf36f39f0b3f46e805447228be66ce012
25 changes: 17 additions & 8 deletions adafruit_character_lcd/character_lcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ def display(self, enable):
@property
def message(self):
"""Display a string of text on the character LCD.
Start position is (0,0) if cursor_position is not set.
If cursor_position is set, message starts at the set
position from the left for left to right text and from
the right for right to left text. Resets cursor column
and row to (0,0) after displaying the message.

The following example displays, "Hello, world!" on the LCD.

Expand Down Expand Up @@ -346,23 +351,27 @@ def message(self, message):
for character in message:
# If this is the first character in the string:
if initial_character == 0:
# Start at (1, 1) unless direction is set right to left, in which case start
# on the opposite side of the display.
# start at self.column instead of 0
col = self.column if self.displaymode & _LCD_ENTRYLEFT > 0 else self.columns - 1
# Start at (0, 0) unless direction is set right to left, in which case start
# on the opposite side of the display if cursor_position not set or (0,0)
# If cursor_position is set then starts at the specified location for
# LEFT_TO_RIGHT. If RIGHT_TO_LEFT cursor_position is determined from right.
# allows for cursor_position to work in RIGHT_TO_LEFT mode
col = self.column if self.displaymode & _LCD_ENTRYLEFT > 0 else self.columns - 1 - self.column
self.cursor_position(col, line)
initial_character += 1
# If character is \n, go to next line
if character == '\n':
line += 1
# Start the second line at (1, 1) unless direction is set right to left in which
# case start on the opposite side of the display.
# start at self.column instead of 0
col = self.column if self.displaymode & _LCD_ENTRYLEFT > 0 else self.columns - 1
# Start the second line at (0, 1) unless direction is set right to left in which
# case start on the opposite side of the display if cursor_position is (0,0) or not set.
# Start second line at same column as first line when cursor_position is set
self.cursor_position(col, line)
# Write string to display
else:
self._write8(ord(character), True)
# reset column and row to (0,0) after message is displayed
self.column, self.row = 0, 0


def move_left(self):
"""Moves displayed text left one column.
Expand Down