Освой MicroPython играючи
/* Моя кошка замечательно разбирается в программировании. Стоит мне объяснить проблему ей - и все становится ясно. */
John Robbins, Debugging Applications, Microsoft Press, 2000
from m5stack import lcd
lcd.font(lcd.FONT_UNICODE)
lcd.clear()
lcd.setCursor(0, 0)
lcd.print('Привет, Мурзик!')
9 bit-mapped fornts and one vector 7-segment font are included. Unlimited number of fonts from file can also be used.
The following font constants are defined and can be used as font arguments:
FONT_Default, FONT_DefaultSmall, FONT_DejaVu18, FONT_Dejavu24, FONT_Ubuntu, FONT_Comic, FONT_Minya, FONT_Tooney, FONT_Small, FONT_7seg, FONT_UNICODE
Draw the pixel at position (x,y).
If color is not given, current foreground color is used.
Get the pixel color value at position (x,y).
Draw the line from point (x,y) to point (x1,y1)
If color is not given, current foreground color is used.
Draw the line from point (x,y) with length lenght starting st distance start from center.
If color is not given, current foreground color is used.
The angle is given in degrees (0~359).
Draw the triangel between points (x,y), (x1,y1) and (x2,y2).
If color is not given, current foreground color is used.
If fillcolor is given, filled triangle will be drawn.
Draw the circle with center at (x,y) and radius r.
If color is not given, current foreground color is used.
If fillcolor is given, filled circle will be drawn.
Draw the circle with center at (x,y) and radius r.
If color is not given, current foreground color is used.
*opt argument defines the ellipse segment to be drawn, default id 15, all ellipse segments.
Multiple segments can drawn, combine (logical or) the values.
If fillcolor is given, filled elipse will be drawn.
Draw the arc with center at (x,y) and radius r, starting at angle start and ending at angle end
The thicknes of the arc outline is set by the thick argument
If fillcolor is given, filled arc will be drawn.
Draw the polygon with center at (x,y) and radius r, with number of sides sides
The thicknes of the polygon outline is set by the thick argument
If fillcolor is given, filled polygon will be drawn.
If rotate is given, the polygon is rotated by the given angle (0~359)
Draw the rectangle from the upper left point at (x,y) and width width and height height
If fillcolor is given, filled rectangle will be drawn.
Draw the rectangle with rounded corners from the upper left point at (x,y) and width width and height height
Corner radius is given by r argument.
If fillcolor is given, filled rectangle will be drawn.
Clear the screen with default background color or specific color if given.
Clear the current display window with default background color or specific color if given.
Set the display orientation.
Use one of predifined constants:
lcd.PORTRAIT, lcd.LANDSCAPE, lcd.PORTRAIT_FLIP, lcd.LANDSCAPE_FLIP
Set the active font and its characteristics.
Argument | Description |
---|---|
font | required, use font name constant or font file name |
rotate | optional, set font rotation angle (0~360) |
transparent | only draw font's foreground pixels |
fixedwidth | draw proportional font with fixed character width, max character width from the font is used |
dist | only for 7-seg font, the distance between bars |
width | only for 7-seg font, the width of the bar |
outline | only for 7-seg font, draw the outline |
color | font color, if not given the current foreground color is used |
lcd.font(lcd.FONT_UNICODE)
Set characteristics of the 7-segment font
Argument | Description |
---|---|
dist | the distance between bars |
width | the width of the bar |
outline | outline color |
color | fill color |
Return width and height of the active font
Display the string text at possition (x,y).
If color is not given, current foreground color is used.
Display the string text at possition (x,y).
If color is not given, current foreground color is used.
Return the width of the string text using the active font fontSize
Clear the the screen area used by string text at possition (x,y) using the bacckground color color.
If color is not given, current background color is used.
Display the image from the file file on position (x,y)
scale (jpg): image scale factor: 0 to 3; if scale>0, image is scaled by factor 1/(2^scale) (1/2, 1/4 or 1/8)
scale (bmp): image scale factor: 0 to 7; if scale>0, image is scaled by factor 1/(scale+1)
type: optional, set the image type, constants lcd.JPG or lcd.BMP can be used. If not set, file extension and/or file content will be used to determine the image type.
lcd.image(100, 100, file="res/default.jpg", scale=0, type=lcd.JPG)
Set active display window to screen rectangle (x,y) - (x1,y1)
Reset active display window to full screen size.
Save active display window dimensions.
Restore active display window dimensions previously saved wint savewin().
Return the display size, (width, height)
Return the active display window size, (width, height)
Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.
Returns 24-bit integer value suitable to be used as color argiment
Arguments
Compile the source font file (must have .c extension) to the binary font file (same name, .fon extension) which can be used as external font.
If debug=True the information about compiled font will be printed.
You can create the c source file from any tft font using the included ttf2c_vc2003.exe program. See README for instructions.
You can create c source file or .fon file from tft font using online converter.