lcd (screen display)
Function
lcd.init(type=1, freq=15000000, color=lcd.BLACK, invert = 0, lcd_type = 0)
Initialize the LCD
screen display
Parameters
type
: Type of device (reserved for future use):0
: None1
: lcd shield (default value)2
: Maix Cube5
: sipeed rgb screen adapter board
type is a key-value parameter, which must be explicitly called by writing type= in the function call
freq
: the frequency ofLCD
(actually refers to the communication rate ofSPI
)color
: The color initialized byLCD
, which can be a 16-bitRGB565
color value, such as0xFFFF
; or aRGB888
tuple, such as(236, 36, 36)
, which defaults tolcd. BLACK
invert
:LCD
inverted color displaylcd_type
: lcd type:0
: default type1
: LCD_TYPE_ILI94862
: LCD_TYPE_ILI94813
: LCD_TYPE_5P0_7P0, a 5-inch or 7-inch LCD with a resolution of 800 * 480 (requires a sipeed adapter board)4
: LCD_TYPE_5P0_IPS, 5-inch IPS LCD with a resolution of 854*489 (requires sipeed adapter board)5
: LCD_TYPE_480_272_4P3, 4.3-inch LCD with a resolution of 480*272 (sipeed adapter board required)
MaixCube and MaixAmigo need to configure the power chip before using the LCD, otherwise the screen will be blurred. In this step, the MaixPy firmware will be configured automatically, no manual operation is required, the user only needs to understand.
lcd.deinit()
Log off the LCD
driver and release the I/O pins
lcd.width()
Returns the width of LCD
(horizontal resolution)
lcd.height()
Returns the height (vertical resolution) of LCD
.
lcd.type()
Return the type of LCD
(reserved for future use):
0: None
1: lcd Shield
lcd.freq(freq)
Set or get the frequency of LCD
(SPI)
Paremeters
freq
: LCD (SPI) frequency
Return
LCD frequency
lcd.set_backlight(state)
Set the backlight status of LCD
, turning off the backlight will greatly reduce the power consumption of the LCD expansion board
Not implemented
Parameters
state
: backlight brightness, value [0,100]
lcd.get_backlight()
Back to backlight state
return value
Backlight brightness, value [0,100]
lcd.display(image, roi=Auto)
Display an image (GRAYSCALE or RGB565) on the LCD screen.
roi is a rectangular tuple (x, y, w, h) of a region of interest. If not specified, it is the image rectangle
If the roi width is smaller than the lcd width, use a vertical black border to center the roi in the center of the screen (that is, fill the unoccupied area with black).
If the width of roi is greater than the width of lcd, the roi is at the center of the screen, and the mismatched pixels will not be displayed (that is, the LCD screen displays the center of roi in the form of a window).
If the height of roi is less than the height of lcd, use a vertical black border to make roi in the center of the screen (that is, fill the unoccupied area with black).
If the height of roi is greater than the height of lcd, the roi is at the center of the screen, and the mismatched pixels will not be displayed (that is, the LCD screen displays the center of roi in the form of a window).
roi is a key-value parameter, which must be explicitly called by writing roi= in the function call.
oft
: Set the offset coordinate, after setting this coordinate, the surrounding will not be automatically filled
lcd.clear()
Clear the LCD screen to black or the specified color.
Parameters
color
: The color initialized byLCD
, which can be a 16-bitRGB565
color value, such as0xFFFF
; or a tuple ofRGB888
, such as(236, 36, 36)
lcd.direction(dir)
It has been abandoned after v0.3.1
, please use lcd.rotation
and lcd.invert
instead, do not use it unless necessary, the interface will still be reserved for debugging
Set the screen orientation, and whether to mirror, etc.
Parameters
dir
: Under normal circumstances,lcd.YX_LRUD
andlcd.YX_RLDU
are recommended, and there are other values, just exchangeXY
orLR
orDU
lcd.rotation(dir)
Set LCD
screen orientation
Parameters
dir
: value range [0,3], rotate clockwise from0
to3
return value
Current direction, value [0,3]
lcd.mirror(invert)
Set whether LCD
is displayed on mirror
Parameters
invert
: Whether to display in mirror,True
orFalse
return value
The current setting, whether to display in a mirror, return to True
or False
lcd.bgr_to_rgb(enable)
Set whether to enable bgr color display
Parameters
enable
: Whether to enable bgr display,True
orFalse
lcd.fill_rectangle(x, y, w, h, color)
Fill a rectangle area on LCD
Parameters
x
: start coordinatex
x
: starting coordinatey
w
: padding widthh
: Fill heightcolor
: Fill color, which can be a tuple, such as(255, 255, 255)
, orRGB565``uint16
value, such as red0x00F8
Routine
Example 1: Display English
import lcd
lcd.init()
lcd.draw_string(100, 100, "hello maixpy", lcd.RED, lcd.BLACK)
Example 2: Display picture
import lcd
import image
img = image.Image("/sd/pic.bmp")
lcd.display(img)
Example 3: Display English by displaying pictures
import lcd
import image
img = image.Image()
img.draw_string(60, 100, "hello maixpy", scale=2)
lcd.display(img)
Example 4: Display the image captured by the camera in real time
import sensor, lcd
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.run(1)
sensor.skip_frames()
lcd.init()
while(True):
lcd.display(sensor.snapshot())