Created
March 21, 2020 16:23
-
-
Save Illizian/b4d68f7bd582921181a0e8c771d2eefd to your computer and use it in GitHub Desktop.
A very simple VirtualLCD implementation (based on the VirtualDOM) for LCD Displays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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