python - 使用 python 代码在 lcd 20x4 上创建自定义字符

标签 python raspberry-pi

我想尝试用一些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/

相关文章:

python - 在 python 中生成 'Ctrl+c' 事件的最佳方法是什么?

python - 使用当前模型 ID 上传 Django 管理文件

python - 在 Dockerfile 中运行 py.test

python - 我想通过串口将函数发送到 RPi 上的 python

opengl - 在 Raspberry Pi 上运行 Open GL 程序?

python - 将多行输入存储到字符串中 (Python)

python - 如何在 python 上减去文件中两行两行的组?

apache - 在树莓派上设置 SSL

c++ - 编译 mpg321 需要 libid3tag - 但已安装 libid3tag

swift - 在树莓派上运行 Swift