LCD类 – LCD屏控制以及LCD触摸¶
LCD类用来控制LCD屏和触摸,通常为320x240分辨率的彩色屏
电阻触摸屏需要连接x和y通道,电容屏通常接I2C接口。LCD对象的使用如下:
lcd = pyb.LCD('X')      # if pyskin is in the X position
lcd = pyb.LCD('Y')      # if pyskin is in the Y position
然后可用这样用:
lcd.light(True)                 # turn the backlight on
lcd.write('Hello world!\n')     # print text to the screen
这个驱动实现了一个可用读写像素值的双缓冲。例如,实现一个点,可用:
x = y = 0
dx = dy = 1
while True:
    # update the dot's position
    x += dx
    y += dy
    # make the dot bounce of the edges of the screen
    if x <= 0 or x >= 127: dx = -dx
    if y <= 0 or y >= 31: dy = -dy
    lcd.fill(0)                 # clear the buffer
    lcd.pixel(x, y, 1)          # draw the dot
    lcd.show()                  # show the buffer
    pyb.delay(50)               # pause for 50ms
构造函数¶
- class pyb.LCD(skin_position)¶
 构建一个LCD对象,并使用指定的位置。
skin_position可以是 ‘X’ 或 ‘Y’ ,并且应该和LCD触摸屏的插入方位匹配。
方法¶
- LCD.command(instr_data, buf)¶
 发送一个属性命令到LCD。 发送 0 给
instr_data作为命令,否则 发送 1 则为数据。buf是要发送的命令或数据的缓冲。
- LCD.contrast(value)¶
 设置LCD的对比度。 有效值在0到47之间。
- LCD.fill(colour)¶
 用指定的颜色填充整个屏幕(0或1代表白或黑)
这个函数写入被隐藏的缓冲区。 使用
show()来显示缓冲区。
- LCD.get(x, y)¶
 获取像素位置
(x, y),返回0或1这个函数从显示缓冲读取。
- LCD.light(value)¶
 开启或关闭背光。 True或1打开,False或0关闭。
- LCD.pixel(x, y, colour)¶
 设置``(x, y)`` 位置的像素为给定的颜色(0或1)
这个函数写入被隐藏的缓冲区。 使用
show()来显示缓冲区。
- LCD.show()¶
 显示隐藏缓冲区到屏幕
- LCD.text(str, x, y, colour)¶
 在给定的位置
(x, y),用给定的颜色(0或1)输出字符这个函数写入被隐藏的缓冲区。 使用
show()来显示缓冲区。
- LCD.write(str)¶
 写字符串
str到屏幕。 其将立即显示。