SPIDisplay类 – SPI显示驱动¶
SPIDisplay
类用于驱动SPI屏。
驱动128x160屏的使用示例:
import sensor, display
# Setup camera.
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.LCD)
sensor.skip_frames()
lcd = display.SPIDisplay()
# Show image.
def loop():
lcd.write(sensor.snapshot())
构造函数¶
- class display.SPIDisplay([width=128[, height=160[, refresh=60[, bgr=False[, byte_swap=False[, triple_buffer[, backlight]]]]]]])¶
width
SPI屏的宽度。默认为128.height
SPI屏的高度。默认为160.refresh
设置LCD屏的刷新率,以Hz为单位。控制SPI屏的时钟。bgr
设置为True,交换红色和蓝色通道。这个参数允许你用我们的驱动更多的屏。byte_swap
设置为True来交换发送的屏的 RGB565的像素字节。这个参数允许你用我们的驱动更多型号的屏。triple_buffer
如果为True使更新屏的非阻塞屏。backlight
specify a backlight controller module to use. By default the backlight will be controlled via a GPIO pin.备注
Uses pins P0, P2, P3, P6, P7, and P8.
方法¶
- SPIDisplay.deinit()¶
Releases the I/O pins and RAM used by the class. This is called automatically on destruction.
- SPIDisplay.width()¶
Returns the width of the screen.
- SPIDisplay.height()¶
Returns the height of the screen.
- SPIDisplay.refresh()¶
Returns the refresh rate.
- SPIDisplay.bgr()¶
返回是否红蓝通道是交换的。
- SPIDisplay.byte_swap()¶
返回是否RGB565像素显示是否是自己交换的。
- SPIDisplay.triple_buffer()¶
返回是否triple buffer使能。
- SPIDisplay.write(image[, x=0[, y=0[, x_scale=1.0[, y_scale=1.0[, roi=None[, rgb_channel=-1[, alpha=256[, color_palette=None[, alpha_palette=None[, hint=0]]]]]]]]]])¶
Displays an
image
whose top-left corner starts at location x, y.You may also pass a path instead of an image object for this method to automatically load the image from disk and draw it in one step. E.g.
write("test.jpg")
.x_scale
控制在水平方向显示图像的缩放参数(浮点数)。如果是负值则进行水平镜像。注意如果没有指定``y_scale`` 则使用x_scale
来保持纵横比。y_scale
控制在垂直方向显示图像的缩放参数(浮点数)。如果是负值则进行垂直翻转。注意如果没有指定``x_scale`` 则使用y_scale
来保持纵横比。roi
是需要显示的感兴趣区域的元组(x, y, w, h)。这能够允许你只对ROI区域进行做法。rgb_channel
是从RGB图像中抽取的RGB通道 (0=R, G=1, B=2) 并显示。例如,如果传rgb_channel=1
,将抽取图像的绿通道,并以灰度图进行显示。alpha
控制图像的透明度。 如果使用256将显示一个透明膜图像。当小于256则产生一个半透明的图像。0则为黑色图像。color_palette
if not-1
can beimage.PALETTE_RAINBOW
,image.PALETTE_IRONBOW
, or a 256 pixel in total RGB565 image to use as a color lookup table on the grayscale value of whatever the input image is. This is applied afterrgb_channel
extraction if used.alpha_palette
if not-1
can be a 256 pixel in total GRAYSCALE image to use as a alpha palette which modulates thealpha
value of the input image being displayed at a pixel pixel level allowing you to precisely control the alpha value of pixels based on their grayscale value. A pixel value of 255 in the alpha lookup table is opaque which anything less than 255 becomes more transparent until 0. This is applied afterrgb_channel
extraction if used.hint
为一个逻辑或标志:image.AREA
: 近邻插值缩小使用的面积参数image.BILINEAR
: 近邻插值的线性缩放。image.BICUBIC
:近邻插值的双立方缩放image.CENTER
: 显示图像置中,在缩放后使用。image.HMIRROR
:水平镜像图像image.VFLIP
: 垂直翻转图像image.TRANSPOSE
: 旋转图像(交换x/y)image.EXTRACT_RGB_CHANNEL_FIRST
: 在缩放前抽取RGB通道。image.APPLY_COLOR_PALETTE_FIRST
: 做法前 使用调色板。image.SCALE_ASPECT_KEEP
: 缩放图像以使用显示。image.SCALE_ASPECT_EXPAND
: 缩放图像以适应显示(剪切)image.SCALE_ASPECT_IGNORE
: 缩放图像以适应显示(伸展)image.ROTATE_90
: 图像旋转90度(即 VFLIP | TRANSPOSE)image.ROTATE_180
: 图像180度旋转(即 HMIRROR | VFLIP)image.ROTATE_270
: 图像旋转270度(即 HMIRROR | TRANSPOSE)
- SPIDisplay.clear([display_off=False])¶
将LCD屏清为黑色。
display_off
如果设置为True则关闭显示并清屏的缓存为黑。应该同时关闭背光,以保证黑屏,因为部分屏关闭显示后会显示为白屏。
- SPIDisplay.backlight([value])¶
设置LCD的背光。0(关)到100(全开)
注意除非你使用
DACBacklight
或PWMBacklight
作为背光,使用GPIO控制管脚将只有0关闭和非0打开。无参数将获取背光值。