Skip to content

Instantly share code, notes, and snippets.

@Illizian
Created March 21, 2020 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Illizian/b4d68f7bd582921181a0e8c771d2eefd to your computer and use it in GitHub Desktop.
Save Illizian/b4d68f7bd582921181a0e8c771d2eefd to your computer and use it in GitHub Desktop.
A very simple VirtualLCD implementation (based on the VirtualDOM) for LCD Displays
from RPi import GPIO
from RPLCD.gpio import CharLCD
# Configure GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
class Display:
def __init__(
self,
cols,
rows,
pin_rs=15,
pin_e=16,
pins_data=[21,22,23,24],
numbering_mode=GPIO.BOARD
):
# Store some of the config we'll need later
self.WIDTH = cols
self.HEIGHT = rows
# Setup our VirtualLCD Screen
self.virtual_rows = [""] * rows
# Setup the LCD Screen
self.LCD = CharLCD(
cols=cols,
rows=rows,
pin_rs=pin_rs,
pin_e=pin_e,
pins_data=pins_data,
numbering_mode=numbering_mode,
auto_linebreaks=True
)
def write(self, row, string):
for i, char in enumerate(string.ljust(self.WIDTH, " ")):
if (len(self.virtual_rows[row]) <= i or self.virtual_rows[row][i] != char):
self.LCD.cursor_pos = (row, i)
self.LCD.write_string(char)
self.virtual_rows[row] = string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment