The screen pixel is 320x240, with the top left corner of the screen as the origin (0,0)
Color codes are predefined and can be used.
Definition | Value | R | G | B |
---|---|---|---|---|
TFT_BLACK | 0x0000 | 0 | 0 | 0 |
TFT_NAVY | 0x000F | 0 | 0 | 128 |
TFT_DARKGREEN | 0x03E0 | 0 | 128 | 0 |
TFT_MAROON | 0x7800 | 128 | 0 | 0 |
TFT_PURPLE | 0x780F | 128 | 0 | 128 |
TFT_OLIVE | 0x7BE0 | 128 | 128 | 0 |
TFT_LIGHTGREY | 0xC618 | 192 | 192 | 192 |
TFT_DARKGREY | 0x7BEF | 128 | 128 | 128 |
TFT_BLUE | 0x001F | 0 | 0 | 255 |
TFT_GREENYELLOW | 0xB7E0 | 180 | 255 | 0 |
TFT_GREEN | 0x07E0 | 0 | 255 | 0 |
TFT_YELLOW | 0xFFE0 | 255 | 255 | 0 |
TFT_ORANGE | 0xFDA0 | 255 | 180 | 0 |
TFT_PINK | 0xFC9F | 255 | 255 | 16 |
TFT_CYAN | 0x07FF | 0 | 255 | 255 |
TFT_DARKCYAN | 0x03EF | 0 | 128 | 128 |
TFT_RED | 0xF800 | 255 | 0 | 0 |
TFT_MAGENTA | 0xF81F | 255 | 0 | 255 |
TFT_WHITE | 0xFFFF | 255 | 255 | 255 |
Description:
Initialize it for use.
Syntax:
begin();
Function argument:
None
Function return value:
None
Note:
1)If you do not want to initialize the LCD with M5.begin( ), call this function before using the display.
Description:
Switch the display to energy saving mode
Syntax:
sleep();
Function argument:
None
Function return value:
None
Note:
-
Call wakeup () function to wake up.
-
Since the LCD backlight of M5Stack is controlled separately, please adjust it with the setBrightness () function if necessary.
Example of use:
#include <M5Stack.h>
M5.Lcd.sleep();
M5.Lcd.setBrightness(0);
Description:
Restore the display from energy saving mode
Syntax:
wakeup();
Function argument:
None
Function return value:
None
Note:
- Since the LCD backlight of M5Stack is controlled separately, please adjust it with the setBrightness () function if necessary.
Example of use:
#include <M5Stack.h>
M5.Lcd.wakeup();
M5.Lcd.setBrightness(200);
Description:
Adjust the display backlight.
Syntax:
setBrightness(uint8_t brightness);
Function argument:
argument | type | Description |
---|---|---|
brightness | uint8_t | Brightness (0: Off - 255:Full) |
Function return value:
None.
Note:
-
The backlight is controlled by PWM (44.1 KHz).
-
Many backlights have a direct effect on battery consumption.
Example of use:
#include <M5Stack.h>
M5.Lcd.setBrightness(200);
Description:
Display a bar that shows the progress.
Syntax:
progressBar(int x, int y, int w, int h, uint8_t val);
Function argument:
argument | type | Description |
---|---|---|
x | int | Coordinate X(left corner) |
y | int | Coordinate Y(left corner) |
w | int | width (px) |
h | int | height(px) |
val | uint8_t | progress(0-100%) |
Function return value:
None
Note:
-
The color is expressed in blue (0x09F1).
-
Please erase the background beforehand to draw only the additional amount.
Example of use:
#include <M5Stack.h>
M5.Lcd.fillRect(0,0,240,20,0);
M5.Lcd.progressBar(0,0,240,20, 20);
Description:
Generate a QR code.
Syntax:
qrcode(const char *string, uint16_t x, uint16_t y, uint8_t width, uint8_t version);
qrcode(const String &string, uint16_t x, uint16_t y, uint8_t width, uint8_t version);
Function argument:
argument | type | Description |
---|---|---|
val | string / String& | String to embed in QR |
x | uint16_t | Coordinate X(left corner) |
y | uint16_t | Coordinate Y(left corner) |
width | uint8_t | width (px) |
version | uint8_t | QR code version |
Function return value:
None
Note:
- Please indicate the appropriate QR code version according to the number of characters.
Example of use:
#include <M5Stack.h>
M5.Lcd.qrcode("http://www.m5stack.com",50,10,220,6);
Description:
Draw a bitmap
Syntax:
drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint16_t *data);
drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, uint16_t *data);
drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint16_t *data, uint16_t transparent);
drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint8_t *data);
drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, uint8_t *data);
Function argument:
argument | type | Description |
---|---|---|
x0 | uint16_t | Coordinate X(left corner) |
y0 | uint16_t | Coordinate Y(left corner) |
w | int16_t | width (px) |
h | int16_t | height(px) |
data | uint16_t* / uint8_t* | image data |
transparent | uint16_t | Transparent color code |
Function return value:
None
Note:
- The color code is expressed by a total of 16 bits: red 5 bits, green 6 bits and blue 5 bits from the top.
Example of use:
See sample sketch:M5Stack->Advanced->drawXBitmap
Description:
Read a bitmap from a file and draw it.
Syntax:
drawBmpFile(fs::FS &fs, const char *path, uint16_t x, uint16_t y);
Function argument:
argument | type | Description |
---|---|---|
fs | fs::FS | File stream |
path | const char * | file path |
x | int16_t | Coordinate X(left corner) |
y | int16_t | Coordinate Y(left corner) |
Function return value:
None
Note:
- It may not be possible to expand depending on the size and the number of bits.
Example of use:
#include <M5Stack.h>
M5.Lcd.drawBmpFile(SD, "/p2.bmp",0,0);
?>We provide a script that can be used to convert jpg
images -> .c
files, you can use it to convert some personal images and draw them on the screen using the following API.bin2code.py
Description:
Read JPEG data from memory and draw it.
Syntax:
void drawJpg(const uint8_t *jpg_data, size_t jpg_len, uint16_t x = 0, uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, uint16_t offX = 0, uint16_t offY = 0, jpeg_div_t scale = JPEG_DIV_NONE);
Function argument:
argument | type | Description |
---|---|---|
jpg_data | uint8_t * | top of data |
jpg_len | size_t | data length |
x | uint16_t | Coordinate X (left corner) |
y | uint16_t | Coordinate Y (left corner) |
maxWidth | uint16_t | Maximum width (px) |
maxHeight | uint16_t | Maximum height (px) |
offX | uint16_t | offset X (px) |
offY | uint16_t | offset Y (px) |
scale | jpeg_div_t | scale |
scale (jpeg_div_t):
Definition | Description |
---|---|
JPEG_DIV_NONE | no care. |
JPEG_DIV_2 | 1/2 |
JPEG_DIV_4 | 1/4 |
JPEG_DIV_8 | 1/8 |
JPEG_DIV_MAX | MAX |
Function return value:
None
Note:
- Depending on the size, the number of bits and the format (progressive etc.), it may not be possible to expand.
Description:
Read JPEG data from a file and draw it.
Syntax:
void drawJpgFile(fs::FS &fs, const char *path, uint16_t x = 0, uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, uint16_t offX = 0, uint16_t offY = 0, jpeg_div_t scale = JPEG_DIV_NONE);
Function argument:
argument | type | Description |
---|---|---|
fs | fs::FS & | file stream |
path | const char * | file path |
x | uint16_t | Coordinate X(left corner) |
y | uint16_t | Coordinate Y(left corner) |
maxWidth | uint16_t | Max Width (px) |
maxHeight | uint16_t | Max Height (px) |
offX | uint16_t | Offset X (px) |
offY | uint16_t | Offset Y (px) |
scale | jpeg_div_t | Scale |
Scale(jpeg_div_t):
Definition | Description |
---|---|
JPEG_DIV_NONE | no care. |
JPEG_DIV_2 | 1/2 |
JPEG_DIV_4 | 1/4 |
JPEG_DIV_8 | 1/8 |
JPEG_DIV_MAX | MAX |
Function return value:
None
Note:
- Depending on the size and format (progressive etc.), it may not be possible to expand.
Syntax:
fillScreen(uint16_t color);
Function: Fill the entire screen with the specified color.
Param | Description |
---|---|
color | the color to be filled |
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.fillScreen(RED);
Syntax:
setTextColor(uint16_t color, uint16_t
backgroundcolor);
Function: Set the foreground color and background color of the displayed text.
Param | Description |
---|---|
color | the color of text |
backgroundcolor | the background color of text |
If backgroundcolor is not given, current background color is used
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.setTextColor(RED);
Syntax:
setCursor(uint16_t x0, uint16_t y0);
Function: Move the cursor to (x0, y0).
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.setCursor(100,100);
M5.Lcd.print("Hello");
Syntax:
uint16_t getCursorX(void);
Function: get the cursor of x.
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.print("Hello ");
int X = M5.Lcd.getCursorX();
M5.Lcd.print(X);
Syntax:
uint16_t getCursorY(void);
Function: get the cursor of y.
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.setCursor(0, 20);
M5.Lcd.print("Hello ");
int Y = M5.Lcd.getCursorY();
M5.Lcd.print(Y);
Syntax:
setTextSize(uint8_t);
Function: set the Size of Text.
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.setTextSize(7);
M5.Lcd.print("Hello");
Syntax:
void clear(uint16_t color);
Function: fill color use of clear screen.
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.print("Hello");
delay(2000);
M5.Lcd.clear(BLACK);
Syntax:
drawPixel(int16_t x, int16_t y, uint16_t color);
Function: Draw a point at position (x, y).
Param | Description |
---|---|
color | color value |
If color is not given, current background color is used
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.drawPixel(22,22,RED);
Description:
Blend foreground and background and return new colour.
Syntax:
uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc);
Function argument:
argument | Description | type |
---|---|---|
alpha | transparency | uint8_t |
fgc | Foreground color | uint16_t |
bgc | Background color | uint16_t |
Example of use:
#include <M5Stack.h>
M5.begin();
int val = M5.Lcd.alphaBlend(128, 0X00FF00, 0XFF0000);
M5.Lcd.fillRect(0, 0, 320, 240, val);
M5.Lcd.print(val);
Description:
Draws a straight line of the specified start point to the end point.
Syntax:
drawChar(int16_t uniCode, int32_t x, uint16_t y, uint8_t font);
Function argument:
argument | type | Description |
---|---|---|
uniCode | int32_t | char |
x | int32_t | Coordinate X |
y | uint16_t | coordinate Y |
font | uint32_t | font |
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.drawChar('A', 160, 120, 2);
Description:
draw a long integer.
Syntax:
drawNumber(long long_num, int32_t poX, int32_t poY);
Function argument:
Argument | Type | Description |
---|---|---|
long_num | long | number |
poX | int32_t | coordinate of X |
poY | int32_t | coordinate of Y |
Example of use:
#include <M5Stack.h>
M5.Lcd.drawNumber(12345, 160, 120);
Description:
drawFloat, prints 7 non zero digits maximum
Syntax:
int16_t drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY);
Function argument:
Argument | Type | Description |
---|---|---|
floatNumber | float | number |
dp | uint8_t | Within seven decimal places |
poX | int32_t | coordinate of Y |
poY | int32_t | coordinate of Y |
Example of use:
#include <M5Stack.h>
M5.Lcd.drawFloat(12.345, 3, 160, 120);
Description:
Draw a vertical line from X to Y.
Syntax:
drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color);
Function argument:
Argument | Type | Description |
---|---|---|
x | int16_t | x position of start point |
y | int16_t | y position of start point |
h | int16_t | line length |
color | uint32_t | Line color (optional) |
Example of use:
#include <M5Stack.h>
M5.Lcd.drawFastHLine(0, 0, 12, TFT_GREEN);
Description:
Draw a horizontal line from X to Y.
Syntax:
drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color);
Function argument:
Argument | Type | Description |
---|---|---|
x | int16_t | x position of start point |
y | int16_t | y position of start point |
h | int16_t | line length |
color | uint32_t | Line color (optional) |
Example of use:
#include <M5Stack.h>
M5.Lcd.drawFastHLine(0, 0, 12, TFT_GREEN);
Syntax:
drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
Function: Draw the line from point (x,y) to point (x1,y1).
Param | Description |
---|---|
color | color value |
If color is not given, current background color is used
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.drawLine(0,0,12,12,WHITE);
Syntax:
drawCircleHelper( int32_t x0, int32_t y0, int32_t r, uint8_t cornername, uint32_t color);
Function: Draw a quarter circle with the center at the point x0 and y0, with radius r, and a quarter C, and a color from 0 to 65535
Argument | Type | Description |
---|---|---|
x0 | int32_t | x0 position of center point |
y0 | int32_t | y0 position of center point |
r | int32_t | radius |
cornername | int32_t | quarter corn |
color | uint32_t | color 0~65535 |
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.drawCircleHelper(160, 120, 30, 4, 0XFF00FF);
Syntax:
drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color);
Function: Draw a circle on point(x0, y0), Radis is r with color
Argument | Type | Description |
---|---|---|
x0 | int32_t | x0 position of center point |
y0 | int32_t | y0 position of center point |
r | int32_t | radius |
color | uint32_t | color 0~65535 |
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.drawCircle(160, 120, 30, 0XFF00FF);
Syntax:
fillCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color);
Function: Draw a filled circle on point(x0, y0), Radis is r with color
Argument | Type | Description |
---|---|---|
x0 | int32_t | x0 position of center point |
y0 | int32_t | y0 position of center point |
r | int32_t | radius |
color | uint32_t | color 0~65535 |
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.fillCircle(160, 120, 30, 0XFF00FF);
Syntax:
drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
Function: Draw the triangel between points (x,y), (x1,y1) and (x2,y2).
Param | Description |
---|---|
color | color value |
If color is not given, current background color is used
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.drawTriangle(22,22,69,98,51,22,RED);
Syntax:
fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
Function: Fill the triangel between points (x,y), (x1,y1) and (x2,y2).
Param | Description |
---|---|
color | color value |
If color is not given, current background color is used
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.fillTriangle(22,22,69,98,51,22,RED);
Syntax:
drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
Function: Draw the rectangle from the upper left point at (x,y) and width and height.
Param | Description |
---|---|
x | position of point |
y | position of point |
w | width of rectangle |
h | height of rectangle |
color | Line color.(Optional.) |
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.drawRect(180, 12, 122, 10, BLUE);
Syntax:
fillRect(int16_t x, int16_t y, int16_t w, int16_t h,uint16_t color);
Function: Fill the rectangle from the upper left point at (x,y) and width and height.
Param | Description |
---|---|
x | position of point |
y | position of point |
w | width of rectangle |
h | height of rectangle |
color | Line color.(Optional.) |
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.fillRect(180, 12, 122, 10, BLUE);
Syntax:
drawRoundRect(int16_t x0, int16_t y0, int16_t w,int16_t h, int16_t radius, uint16_t color);
Function: Draw the rectangle with rounded corners from the upper left point at (x,y) and width and height. Corner radius is given by radius argument.
Param | Description |
---|---|
x | position of point |
y | position of point |
w | width of circle |
h | height of circle |
radius | the radius of circle |
color | color value |
If color is not given, current background color is used
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.fillRoundRect(180,70,122,10,4,BLUE);
Description:
Draw a filled square with the upper left point (x, y) and width and height.
Syntax:
fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, [uint16_t color]);
Function argument:
argument | Description | type |
---|---|---|
x | coordinate of the top left corner of the rectangle | int16_t |
y | coordinate of the top left corner of the rectangle | int16_t |
w | width of rectangle | int16_t |
h | height of rectangle | int16_t |
r | corner radius | int16_t |
color | Color of the square line. Optional. | uint16_t |
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.fillRoundRect(180, 70, 122, 10, 4, BLUE);
Description:
Draw an ellipse with the top left point (x, y) and the width and height.
Syntax:
drawEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color);
Function argument:
argument | Description | type |
---|---|---|
x0 | Center X coordinate of the ellipse | int16_t |
y0 | Center Y coordinate of the ellipse | int16_t |
rx | Width of circle | int16_t |
ry | Height of circle | int16_t |
color | circle color | uint16_t |
Example of use:
#include <M5Stack.h>
M5.Lcd.drawEllipse(100,100,20,30, TFT_GREEN);
Description:
Draw a filled ellipse, specifying the top left point (x, y) and the width and height.
Syntax:
fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color);
Function argument:
argument | Description | type |
---|---|---|
x0 | Center X coordinate of the ellipse | int16_t |
y0 | Center Y coordinate of the ellipse | int16_t |
rx | Width of circle | int16_t |
ry | Height of circle | int16_t |
color | circle color | uint16_t |
Example of use:
#include <M5Stack.h>
M5.Lcd.drawEllipse(100,100,20,30, TFT_GREEN);
Description:
Change to the color code (rgb 565) used in the function.
Syntax:
color565(uint8_t red, uint8_t green, uint8_t blue);
Function argument:
Argument | Description | Type |
---|---|---|
red | red | int8_t |
green | green | int8_t |
blue | blue | int8_t |
Function return value:
None
Example of use:
#include <M5Stack.h>
uint16_t colorvalue=0;
colorvalue = M5.Lcd.color565(255,255,255);
Description:
Rotate the screen.
Syntax:
setRotation(uint8_t r);
Function argument:
argument | type | Description |
---|---|---|
r | uint8_t | Rotation angle r (unit:90 deg) |
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.setRotation(1);
Note:
-
The display control of M5Stack is rotated by 90 °, and setRotation (1) is executed in M5.Lcd.begin ().
-
0 to 3 rotate, 4 to 7 reverse and rotate.
Description:
Reverse the screen color in negative / positive.
Syntax:
invertDisplay(boolean i);
Function argument:
Argument | Type | Description |
---|---|---|
i | boolean | true : inverted |
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.invertDisplay(true);
Description:
Load a font
Syntax:
loadFont(String fontName, fs::FS &ffs);
Function argument:
argument | type | Description |
---|---|---|
fontName | String | font filepath |
ffs | fs::FS | file stream |
Example of use:
#include <M5Stack.h>
M5.Lcd.loadFont("filename", SD);
Description:
Whether to automatically wrap the display
Syntax:
setTextWrap(boolean wrapX, boolean wrapY)
Function argument:
argument | type | Description |
---|---|---|
wrapX | boolean | X direction |
wrapY | boolean | Y direction |
Example of use:
#include <M5Stack.h>
M5.Lcd.setTextWrap(ture, true);
Description:
Set the text position reference datum
Syntax:
setTextDatum(uint8_t datum)
Function argument:
argument | type | Description |
---|---|---|
TL_DATUM | uint8_t | Top left (default) |
TC_DATUM | uint8_t | Top centre |
TR_DATUM | uint8_t | Top right |
ML_DATUM | uint8_t | Middle left |
MC_DATUM | uint8_t | Middle centre |
MR_DATUM | uint8_t | Middle right |
BL_DATUM | uint8_t | Bottom left |
BC_DATUM | uint8_t | Bottom centre |
BR_DATUM | uint8_t | Bottom right |
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.setTextDatum(MC_DATUM);
M5.Lcd.drawString("hello", 160, 120, 2);
Description:
text background padding some pixel to over-write the old text
Syntax:
setTextPadding(uint16_t x_width)
Function argument:
argument | type | Description |
---|---|---|
x_width | uint16_t | Blanked area will be width of pixels |
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.drawString("Orbitron 32", 160, 60,2);
delay(2000);
M5.Lcd.setTextPadding(M5.Lcd.width() - 20);
M5.Lcd.drawString("Orbitron 32 with padding", 160, 60, 2);
Description:
Return the rotation value (as used by setRotation())
Syntax:
uint8_t getRotation(void)
Function argument:
None
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.print(M5.Lcd.getRotation());
Description:
Return the pixel width of display (per current rotation)
Syntax:
int16_t width(void)
Function argument:
None
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.print(M5.Lcd.width());
Description:
Return the pixel height of display (per current rotation)
Syntax:
int16_t height(void)
Function argument:
None
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.print(M5.Lcd.height());
Description:
Return the width in pixels of a string in a given font
Syntax:
int16_t textWidth(const String& string)
Function argument:
argument | type | Description |
---|---|---|
string | const String& | text String |
Example of use:
#include <M5Stack.h>
M5.begin();
String text = "hello ";
M5.Lcd.print(text);
M5.Lcd.print(M5.Lcd.textWidth(text));
Description:
Return the text datum value (as used by setTextDatum())
Syntax:
uint8_t setRotation(void)
Function argument:
None
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.setTextDatum(MC_DATUM);
M5.Lcd.print(M5.Lcd.getTextDatum());
##int16_t fontHeight()
Description:
rn the height of a font (yAdvance for free fonts)
Syntax:
int16_t fontHeight(void)
Function argument:
None
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.print(M5.Lcd.fontHeight());
##drawCentreString()
Description:
draw string centred on dX
Syntax:
int16_t drawCentreString(const String& string, int32_t dX, int32_t poY, uint8_t font)
Function argument:
argument | type | Description |
---|---|---|
string | const String& | text String |
dX | int32_t | center point on dX |
poY | int32_t | coordinate Y |
font | uint8_t | font name |
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.drawCentreString("hello", 160, 0, 2);
Description:
draw string right justified to dX,deprecated, use setTextDatum()
Syntax:
int16_t drawRightString(const String& string, int32_t dX, int32_t poY, uint8_t font)
Function argument:
argument | type | Description |
---|---|---|
string | const String& | text String |
dX | int32_t | Right eage on dX |
poY | int32_t | coordinate Y |
font | uint8_t | font name |
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.drawRightString("hello", 160, 0, 2);
Description:
rn the height of a font (yAdvance for free fonts)
Syntax:
int16_t fontHeight(void)
Function argument:
None
Example of use:
#include <M5Stack.h>
M5.begin();
M5.Lcd.print(M5.Lcd.fontHeight());
Description:
Finish using a font
Syntax:
unloadFont();
Function argument:
None
Example of use:
#include <M5Stack.h>
M5.Lcd.unloadFont();
Description:
Returns whether you are loading a font
Syntax:
fontsLoaded();
Function argument:
None
Function return value:
値 | Description |
---|---|
true | loaded |
false | Unread |
Example of use:
#include <M5Stack.h>
if(M5.Lcd.unloadFont()){
M5.Lcd.unloadFont();
}
Syntax:
print();
Function: Start printing text at the current position of the screen.
The specified content is printed in the foreground color by default.
Example:
#include <M5Stack.h>
M5.begin();
M5.Lcd.print("this is a print text function");
Description:
Draw a character
Syntax:
drawString(const char *string, int32_t poX, int32_t poY, uint8_t font);
drawString(const char *string, int32_t poX, int32_t poY);
drawString(const String& string, int32_t poX, int32_t poY, uint8_t font);
drawString(const String& string, int32_t poX, int32_t poY);
Function argument:
argument | type | Description |
---|---|---|
poX | int32_t | Coordinate X (upper left) |
poY | int32_t | Coordinate Y (upper left) |
string | const char * / String & | String |
font | uint8_t | 1: If use the loaded font |
Function return value:
None
Description:
Draw the specified string.
Syntax:
printf("Format specification",arg1...);
Note:
The format specification can be specified according to the usual C language format.
Example of use:
#include <M5Stack.h>
int a=1;
M5.begin();
M5.Lcd.printf("A=%d",a);
##createSprite()
Description:
Create a sprite of width x height pixels, return a pointer to the RAM area
Syntax:
void* createSprite(int16_t w, int16_t h)
Function argument:
argument | type | Description |
---|---|---|
w | int16_t | create sprite width |
h | int16_t | create sprite height |
Example of use:
#include <M5Stack.h>
M5.begin();
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
img.createSprite(70, 80);
Description:
Delete the sprite to free up memory (RAM)
Syntax:
deleteSprite(void)
Function argument:
None
Example of use:
#include <M5Stack.h>
M5.begin();
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
img.createSprite(70, 80);
img.deleteSprite();
Description:
set the colour depth to 1, 8 or 16 bits,Can be used to change depth an existing sprite
Syntax:
void setColorDepth(int8_t bit)
Function argument:
argument | type | Description |
---|---|---|
bit | int8_t | color depth bits |
Example of use:
#include <M5Stack.h>
M5.begin();
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
img.setColorDepth(8);
img.createSprite(70, 80);
Description:
Fill the whole sprite with defined colour
Syntax:
void fillSprite(uint32_t color)
Function argument:
argument | type | Description |
---|---|---|
color | int32_t | filled color |
Example of use:
#include <M5Stack.h>
M5.begin();
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
img.createSprite(70, 80);
img.fillSprite(WHITE);
Description:
Push the sprite to the TFT at x, y,Optionally a "transparent" colour can be defined, pixels of that colour will not be rendered
Syntax:
void pushSprite(int32_t x, int32_t y, uint16_t transparent)
Function argument:
argument | type | Description |
---|---|---|
x | int32_t | coordinate x |
y | int32_t | coordinate y |
transparent | int16_t | optional |
Example of use:
#include <M5Stack.h>
M5.begin();
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
img.createSprite(70, 80);
img.pushSprite(35, 40, WHITE);
Description:
Return the width of the sprite
Syntax:
int16_t width(void)
Function argument:
None
Example of use:
#include <M5Stack.h>
M5.begin();
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
img.createSprite(70, 80);
M5.Lcd.print(img.width());
Description:
Return the height of the sprite
Syntax:
int16_t height(void)
Function argument:
None
Example of use:
#include <M5Stack.h>
M5.begin();
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
img.createSprite(70, 80);
M5.Lcd.print(img.height());
#include <M5Stack.h>
M5.begin();
M5.Lcd.fillScreen(BLACK) #set the default background color
M5.Lcd.drawLine(0, 0, WHITE);
M5.Lcd.drawTriangle(22, 22, 69, 98, 51, 22, RED);
M5.Lcd.fillTriangle(122, 122, 169, 198, 151, 182, RED);
M5.Lcd.drawRect(180, 12, 122, 10, BLUE);
M5.Lcd.fillRect(180, 30, 122, 10, BLUE);
M5.Lcd.drawRoundRect(180, 50, 122, 10, 4, BLUE);
M5.Lcd.fillRoundRect(180, 70, 122, 10, 4, BLUE);
M5.Lcd.print("this is a print text function");