Skip to content

Instantly share code, notes, and snippets.

@Illizian
Created Mar 21, 2020
Embed
What would you like to do?
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