Created
February 4, 2020 06:13
-
-
Save robobenklein/6e4eeb18360fd2dfdcd9574213fe47ea to your computer and use it in GitHub Desktop.
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
import serial | |
import time | |
import fileinput | |
port = serial.Serial('/dev/ttyUSB0',19200,serial.EIGHTBITS,serial.PARITY_NONE, | |
serial.STOPBITS_ONE,timeout=5,rtscts = False) | |
def wr(m): | |
port.write(m) | |
NULL = '\x00' | |
CLEAR = ''.join([chr(254), chr(88)]) | |
WRAPON = ''.join([chr(254), chr(67)]) | |
WRAPOFF = ''.join([chr(254), chr(68)]) | |
SCROLLON = ''.join([chr(254), chr(81)]) | |
SCROLLOFF = ''.join([chr(254), chr(82)]) | |
CURBLINK = ''.join([chr(254), chr(83)]) | |
CURNOBLINK = ''.join([chr(254), chr(84)]) | |
CURHOME = ''.join([chr(254), chr(72)]) | |
CURPOS = ''.join([chr(254), chr(71)]) # then col, row | |
def curpos(row, col = 0): | |
# [0-19] -> 1-20 | |
port.write(CURPOS) | |
port.write(chr(col+1)) | |
port.write(chr(row+1)) | |
CURMOVELEFT = ''.join([chr(254), chr(76)]) | |
CURMOVERIGHT = ''.join([chr(254), chr(77)]) | |
BRIGHTNESS = ''.join([chr(254), chr(89)]) | |
def brightness(val = 0): | |
# [0 to 3] larger = darker | |
# 0 = 100% | |
# 3 = 25% | |
port.write(BRIGHTNESS) | |
port.write(chr(val)) | |
DISPLAYON = ''.join([chr(254), chr(66), chr(0)]) | |
DISPLAYOFF = ''.join([chr(254), chr(70)]) | |
wr(CURHOME) | |
wr(WRAPOFF) | |
wr(SCROLLOFF) | |
brightness(3) | |
row = 0 | |
for line in fileinput.input(): | |
curpos(row) | |
l = (line.strip()).ljust(20)[:20] | |
wr(l) | |
print("'%s'" % l) | |
row = (row + 1) % 4 | |
curpos(3, 19) | |
""" | |
curpos(1,0) | |
wr("one") | |
curpos(2,0) | |
wr("two") | |
curpos(3,0) | |
wr("three") | |
curpos(4,0) | |
wr("four") | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment