我想尝试用一些Python代码在LCD 20x4上制作一个大字符。
我之前已经使用 adafruit 库在 LCD 16x2 上显示了一些数据和文本,但现在我尝试在 LCD 20x4 上显示自定义字符,并且有点困惑。我认为下面的代码(来自 adafruit 库)对于制作自定义字符很有用,但我不知道如何使用它。任何人都可以提供有关如何执行此操作的指导吗?
def create_char(self, location, pattern):
"""Fill one of the first 8 CGRAM locations with custom characters.
The location parameter should be between 0 and 7 and pattern should
provide an array of 8 bytes containing the pattern. E.g. you can easyly
design your custom character athttp://www.quinapalus.com/hd44780udg.html
To show your custom character use eg. lcd.message('\x01')
"""
# only position 0..7 are allowed
location &= 0x7
self.write8(LCD_SETCGRAMADDR | (location << 3))
for i in range(8):
self.write8(pattern[i], char_mode=True)
最佳答案
使用链接中的工具生成模式,然后将十进制版本作为第二个参数中的列表传递给该函数,例如
lcd.create_char(1, [0,10,21,17,10,4,0])
将字符 1 定义为心形。完成此操作后,您可以在字符串中包含 \x01
来打印该字符。
正如文档中所暗示的,同样的想法适用于从 0 到 7 的任何字符代码。只需将 create_char()
的第一个参数替换为该范围内的另一个数字即可。
关于python - 使用 python 代码在 lcd 20x4 上创建自定义字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30017357/