pdf-icon

LCD Screen

Core2 screen pixel resolution is 320x240, with the top-left corner as the origin (0,0)

Color Codes:

Name Hexadecimal R G B
BLACK 0x0000 0 0 0
NAVY 0x000F 0 0 128
DARKGREEN 0x03E0 0 128 0
MAROON 0x7800 128 0 0
PURPLE 0x780F 128 0 128
OLIVE 0x7BE0 128 128 0
LIGHTGREY 0xC618 192 192 192
DARKGREY 0x7BEF 128 128 128
BLUE 0x001F 0 0 255
GREENYELLOW 0xB7E0 180 255 0
GREEN 0x07E0 0 255 0
YELLOW 0xFFE0 255 255 0
ORANGE 0xFDA0 255 180 0
PINK 0xFC9F 255 255 16
CYAN 0x07FF 0 255 255
DARKCYAN 0x03EF 0 128 128
RED 0xF800 255 0 0
MAGENTA 0xF81F 255 0 255
WHITE 0xFFFF 255 255 255

Class name: Lcd

begin()

Description:

Initialize for use

Function prototype:

void begin()

Note:
If you do not wish to use M5.begin() to initialize the LCD, please call this function before using the display.

Usage example:

#include <M5Core2.h>

void setup() {
  M5.Lcd.begin();  // Initialize M5Stack
}

void loop() {
}

sleep()

Description:

Switch the display to power-saving mode

Function prototype:

void sleep()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.Lcd.begin();  // Initialize M5Core2
  M5.Lcd.sleep();   // Switch to sleep mode
}

void loop() {
}

clear()

Description:

Clear the contents displayed on the screen

Function prototype:

void clear()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.Lcd.begin();  // Initialize M5Core2
  M5.Lcd.fillScreen(RED);
  delay(1000);
  M5.Lcd.clear();   // Clear the contents displayed on the screen
}

void loop() {
}

wakeup()

Description:

Resume display from power-saving mode

Function prototype:

void wakeup()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.Lcd.begin();  // Initialize M5Core2
  M5.Lcd.wakeup();  // Resume display from power-saving mode
}

void loop() {
}

hight()

Function:

Returns the screen height.

Function prototype:

void hight()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  M5.Lcd.print(M5.Lcd.height());    // Display the screen height on the screen
}

void loop() {
}

width()

Function:

Returns the screen width.

Function prototype:

void width()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  M5.Lcd.print(M5.Lcd.width()); // Display the screen width on the screen
}

void loop() {
}

getCursorX()

Function:

Gets the x-coordinate at the end of the character.

Function prototype:

int16_t getCursorX()

Note:
Not applicable to drawNumber()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.print("Hello");
  int X = M5.Lcd.getCursorX();
  M5.Lcd.print(X);
}

void loop(){
}

getCursorY()

Function:

Gets the y-coordinate at the end of the character.

Function prototype:

int16_t getCursorY()

Note:
Not applicable to drawNumber()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.print("Hello");
  int X = M5.Lcd.getCursorY();
  M5.Lcd.print(Y);
}

void loop(){
}

getRotation()

Function:

Returns the screen rotation direction.

Function prototype:

uint8_t getRotation()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.print(M5.Lcd.getRotation());   // Output the screen rotation direction on the screen
}

void loop(){
}

getTextDatum()

Function:

Returns the text alignment method (number in the list above).

Function prototype:

textdatum_t getRotation()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.setTextDatum(MC_DATUM);    // Set the text alignment method
  M5.Lcd.drawString("hello", 160, 120, 2);  // Print the string hello at (160,120) with font size 2
  M5.Lcd.print(M5.Lcd.getTextDatum());  // Print the obtained text alignment method on the screen
}

void loop(){
}

setCursor()

Function:

Sets the text cursor at (x,y).

Function prototype:

void setCursor(int16_t x, int16_t y)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();             // Initialize M5Core2
  M5.Lcd.setCursor(0, 30);
  M5.Lcd.printf("Hello M5");
}

void loop() {}

setRotation()

Function:

Rotates the screen.

Function prototype:

void setRotation(uint8_t m)

Note:
1. The rotation angle must be a multiple of 90°
2. 0-3 are clockwise rotations, 4-7 are counterclockwise rotations (default is 1)
3. Must be set before display

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();             // Initialize M5Core2
  M5.Lcd.setRotation(2);  // Rotate the screen 180 degrees clockwise (2*90)
  M5.Lcd.fillEllipse(160, 100, 60, 100, YELLOW);    // Create a yellow ellipse at (160,100) with major and minor axes of 60,100
  delay(1000);
  M5.Lcd.setRotation(1);  // Restore the screen to its default display state
  M5.Lcd.fillEllipse(160, 100, 60, 100, GREEN);
}

void loop() {}

SetLcdVoltage()

Function:

Sets the screen brightness.

**

Function prototype:**

void SetLcdVoltage(uint16_t voltage)

Note:
The voltage value range is (2500~3300)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();
  M5.Lcd.fillScreen(RED);
}
void loop() {
  M5.update();
  for(int i=2500; i<3300;i++){
    M5.Axp.SetLcdVoltage(i);  // Set the voltage value every 10ms
    delay(10);
  }
  for(int i=3300; i>2500;i--){
    M5.Axp.SetLcdVoltage(i);
    delay(10);
  }
}

alphaBlend()

Function:

Sets the opacity, blending foreground and background colors.

Function prototype:

uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.Lcd.begin();  // Initialize M5Core2
  M5.Lcd.fillScreen(M5.Lcd.alphaBlend(128, 0X00FF00, 0XFF0000));
  // Set foreground, background colors to 0X00FF00, 0XFF0000 respectively, opacity to 128, and fill the entire screen
}

void loop() {
}

setFreeFont()

Function:

Sets the GFX font to use.

Function prototype:

void setFreeFont(const GFXfont *f)

Usage example:

loadFont()

Function:

Loads a font from a VLW file.

Function prototype:

void loadFont(String fontName, bool flash)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.loadFont("filename", SD);
}

void loop() {
}

unloadFont()

Function:

Unloads the font.

Function prototype:

void unloadFont()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.unloadFont();
}

void loop() {
}

fontsLoaded()

Function:

Returns whether custom fonts are loaded.

Function prototype:

uint16_t fontsLoaded(void)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.print(M5.Lcd.fontsLoaded());
}

void loop() {
}

fillScreen()

Function:

Fills the entire screen with the specified color.

Function prototype:

void fillScreen(uint32_t color)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.fillScreen(RED);   // Fill the screen with red
}

void loop(){
}

invertDisplay()

Function:

Inverts the screen color in a negative/positive way.

Function prototype:

void invertDisplay(boolean i)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.fillScreen(RED);   // Fill the screen with red
}

void loop() {
  M5.Lcd.invertDisplay(1);  // Enable inversion
  delay(1000);
  M5.Lcd.invertDisplay(0);  // Disable inversion
}

color565()

Function:

Changes to the color code used in the function (rgb 565).

Function prototype:

color565(uint8_t red, uint8_t green, uint8_t blue)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  uint16_t colorvalue = 0;
  colorvalue = color565(255, 255, 255);
  M5.Lcd.fillEllipse(160, 100, 60, 100, colorvalue);
}

void loop() {}

Text

print()

Function:

Prints a string at the current position on the screen.

Function prototype:

size_t print()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin

();  // Initialize M5Core2
  M5.Lcd.print("this is a print text function");
}

void loop() {
}

textWidth()

Function:

Returns the pixel width occupied by text.

Function prototype:

int16_t textWidth(const String& string)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  String text = "hello  ";
  M5.Lcd.print(text);
  M5.Lcd.print(M5.Lcd.textWidth(text)); // Print the pixel width occupied by the string array text on the screen
}

void loop() {}

setTextSize()

Function:

Sets the size of the displayed text.

Function prototype:

void setTextSize(uint8_t s)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.setTextSize(4);    // Set the font size to 4
  M5.Lcd.print("Hello M5Core2");
}

void loop() {
}

setTextColor()

Function:

Sets the foreground color / Sets the foreground and background colors of the displayed text.

Function prototype:

void setTextColor(uint16_t color)

void setTextColor(uint16_t color, uint16_t backgroundcolor)

Note:
1.If the function's backgroundcolor value is not given, the current background color is used
2.If the text color is not set, the default is white

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin(); // Initialize M5Core2
  M5.Lcd.setTextColor(RED,BLACK);   // Set the text's foreground and background colors to red and black respectively
  //M5.Lcd.setTextColor(RED);
}

void loop(){
}

setTextWrap()

Function:

Enables the auto-wrap function.

Function prototype:

void setTextWrap(boolean wrapX, boolean wrapY)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  M5.Lcd.setTextWrap(true, true);   // Enable auto-wrap for x and y axes
    M5.Lcd.print("hello M5Core2 hello M5Core2 hello M5Core2 hello M5Core2 hello M5Core2 hello M5Core2 hello M5Core2 hello M5Core2");
}

void loop() {}

setTextPadding()

Function:

Fills the specified blank width (helps erase old text and numbers).

Function prototype:

void setTextPadding(uint16_t x_width)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();
}

void loop() {
  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);
  delay(2000);
}

setTextDatum()

Function:

Sets the text alignment method.

Function prototype:

void setTextDatum(uint8_t datum)

Note:
1.Not applicable to print()

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.setTextDatum(MC_DATUM);    // Set the text alignment method to center alignment
  M5.Lcd.drawString("hello", 160, 120, 2);  // Print the string hello at (160,120) with font size 2
}

void loop(){
}

Draw

drawFastHLine()

Function:

Draws a color line of length w horizontally at (X,Y).

Function prototype:

void drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.drawFastHLine(3, 100, 255, GREEN); // Draw a green horizontal line of length 255 at (3,100)
}

void loop() {
}

drawFastVLine()

Description:

Draws a vertical line of color color with length w at position (X, Y).

Function prototype:

void drawFastVLine(int32_t x, int32_t y, int32_t w, uint32_t color)

Parameter Type Description
x int32_t X coordinate
y int32_t Y coordinate
w int32_t Width (in pixels)
color uint32_t Line color (optional)

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.drawFastVLine(100, 0, 255, TFT_GREEN); // Draw a green vertical line of length 255 at (100,0)
}

void loop(){
}

drawString()

Description:

Displays a string at position (x,y).

Function prototype:

int16_t drawString(const char *string, int32_t poX, int32_t poY, uint8_t font)

Parameter Type Description
string const char * A string
poX int32_t X coordinate
poY int32_t Y coordinate
font uint8_t Font

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.drawString("Hello M5", 160, 100, 2);   // Display the string "Hello M5" at (160,100) using font 2
}

void loop(){
}

drawNumber()

Description:

Displays an integer at position (x,y).

Function prototype:

void drawNumber(long long_num, int32_t poX, int32_t poY)

Parameter Type Description
long_num long Number
poX int32_t X coordinate
poY int32_t Y coordinate

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.drawNumber(99, 55, 100);   // Display the number 99 at position (55,100)
}

void loop(){
}

drawChar()

Description:

Displays a character uniCode in font font at position (X, Y).

Function prototype:

int16_t drawChar(int16_t uniCode, int32_t x, uint16_t y, uint8_t font)

Parameter Type Description
uniCode int16_t Character
x int32_t X coordinate
y uint16_t Y coordinate
font uint8_t Font

Usage example:

#include <M5Core2.h>
void setup() {
  M5.begin(); // Initialize M5Core2
  M5.Lcd.drawChar('A', 160, 120, 2);    // Display character 'A' at (160,120) using font 2
}
void loop(){
}

drawFloat()

Description:

Displays a floating-point number floatNumber with dp decimal places at position (X, Y).

Function prototype:

int16_t drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY)

Parameter Type Description
floatNumber float Number to display
dp uint8_t Decimal places
poX int32_t X coordinate
poY int32_t Y coordinate

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  M5.Lcd.drawFloat(3.1415928, 7, 100

, 100);    // Display the floating-point number 3.1415928 with 7 decimal places at (100,100)
}

void loop() {}

drawPixel()

Description:

Draws a pixel at position (X, Y).

Function prototype:

void drawPixel(int32_t x, int32_t y, uint32_t color)

Parameters:

Parameter Type Description
x int32_t X coordinate
y int32_t Y coordinate
color uint32_t Color

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.drawPixel(22, 22, RED);  // Draw a red pixel at (22,22)
}

void loop() {}

drawLine()

Description:

Draws a line from point (x0,y0) to point (x1,y1) in color (color).

Function prototype:

void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color)

Parameter Type Description
x int32_t X coordinate
y int32_t Y coordinate
color uint32_t Color

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.drawLine(200, 0, 200, 200, GREEN);  // Draw a line from point (200,0) to (200,200) in green
}

void loop(){
}

drawRect()

Description:

Draws a rectangle outline at position (x,y) with specified width w, height h, and color color.

Function prototype:

void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)

Parameter Type Description
x int32_t X coordinate
y int32_t Y coordinate
w int32_t Rectangle width (in pixels)
h int32_t Rectangle height (in pixels)
color uint32_t Color value

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.drawRect(180, 12, 122, 10, BLUE);  // Draw a rectangle outline at (180,12) in blue with width 122 and height 10
}

void loop(){
}

fillRect()

Description:

Draws a filled rectangle at position (x,y) with specified width w, height h, and color color.

Function prototype:

void fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)

Parameter Type Description
x int32_t X coordinate
y int32_t Y coordinate
w int32_t Rectangle width (in pixels)
h int32_t Rectangle height (in pixels)
color uint32_t Color value

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.fillRect(150, 120, 122, 10, BLUE); // Draw a filled rectangle at (150,120) in blue with width 122 and height 10
}

void loop(){
}

drawRoundRect()

Description:

Draws a rounded rectangle outline at position (x,y) with specified width w, height h, radius r, and color color.

Function prototype:

`void drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, uint32_t color

)`

Parameter Type Description
x int32_t Rectangle top-left X coordinate
y int32_t Rectangle top-left Y coordinate
w int32_t Rectangle width (in pixels)
h int32_t Rectangle height (in pixels)
r int32_t Corner radius
color uint32_t Line color

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  M5.Lcd.drawRoundRect(55,55,30,50,10,GREEN);   // Draw a green rounded rectangle at (55,55) with width 30, height 50, and corner radius 10
}

void loop() {}

fillRoundRect()

Description:

Draws a filled rounded rectangle at position (x,y) with specified width w, height h, radius r, and color color.

Function prototype:

void fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, uint32_t color)

Parameter Type Description
x int32_t Rectangle top-left X coordinate
y int32_t Rectangle top-left Y coordinate
w int32_t Rectangle width (in pixels)
h int32_t Rectangle height (in pixels)
r int32_t Corner radius
color uint32_t Line color

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  M5.Lcd.fillRoundRect(55, 55, 30, 50, 10, GREEN); // Draw a filled green rounded rectangle at (55,55) with width 30, height 50, and corner radius 10
}

void loop() {}

drawCircle()

Description:

Draws a circle outline at position (x,y) with radius r and color color.

Function prototype:

void drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color)

Parameters:

Parameter Type Description
x0 int32_t Circle center X coordinate
y0 int32_t Circle center Y coordinate
r int32_t Circle radius
color uint32_t Circle color

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  M5.Lcd.drawCircle(100, 100, 50, RED);   // Draw a red circle outline at (100,100) with radius 50
}

void loop() {}

fillCircle()

Description:

Draws a filled circle at position (x,y) with radius r and color color.

Function prototype:

void drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color)

Parameters:

Parameter Type Description
x0 int32_t Circle center X coordinate
y0 int32_t Circle center Y coordinate
r int32_t Circle radius
color uint32_t Circle color

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  M5.Lcd.fillCircle(100, 100, 50, RED); // Draw a filled red circle at (100,100) with radius 50
}

void loop() {}

drawEllipse()

Description:

Draws an ellipse outline at position (x,y) with width rx, height ry, and color color.

Function prototype:

void fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color)

**Parameters

:**

Parameter Type Description
x0 int16_t Ellipse center X coordinate
y0 int16_t Ellipse center Y coordinate
rx int32_t Ellipse width (in pixels)
ry int32_t Ellipse height (in pixels)
color uint16_t Ellipse color

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  M5.Lcd.drawEllipse(160, 100, 60, 100, YELLOW);// Draw a yellow ellipse outline at (160,100) with width 60 and height 100
}

void loop() {}

fillEllipse()

Description:

Draws a filled ellipse at position (x,y) with width rx, height ry, and color color.

Function prototype:

void fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color)

Parameters:

Parameter Type Description
x0 int16_t Ellipse center X coordinate
y0 int16_t Ellipse center Y coordinate
rx int32_t Ellipse width (in pixels)
ry int32_t Ellipse height (in pixels)
color uint16_t Ellipse color

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();  // Initialize M5Core2
  M5.Lcd.fillEllipse(160, 100, 60, 100, YELLOW);    // Draw a filled yellow ellipse at (160,100) with width 60 and height 100
}

void loop() {}

drawTriangle()

Description:

Draws a triangle outline using vertices (x1, y1), (x2, y2), and (x3, y3).

Function prototype:

void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color)

Parameter Type Description
x* int32_t Vertices X* coordinates
y* int32_t Vertices Y* coordinates
color uint32_t Triangle color

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW); // Draw a yellow triangle outline with vertices at (30,30), (180,100), and (80,150)
}

void loop() {}

drawTriangle()

Description:

Draws a filled triangle using vertices (x1, y1), (x2, y2), and (x3, y3).

Function prototype:

void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color)

Parameter Type Description
x* int32_t Vertices X* coordinates
y* int32_t Vertices Y* coordinates
color uint32_t Triangle color

Usage example:

#include <M5Core2.h>

void setup() {
  M5.begin();   // Initialize M5Core2
  M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW); // Draw a filled yellow triangle with vertices at (30,30), (180,100), and (80,150)
}

void loop() {}

drawXBitmap()

Description:

Draws a bitmap.

Syntax:

void drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)

Parameter Type Description
x int16_t X coordinate
y int16_t Y coordinate
bitmap const uint8_t Image to show
w int16_t Width (pixels)
h int16_t Height (pixels)
color uint16_t Color

Example Usage:

See example sketch: M5Stack -> Advanced -> Display -> drawXBitmap

drawBitmap()

Description:

Draws a bitmap.

Function Prototypes:

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)

Parameter Type Description
x0 uint16_t X coordinate
y0 uint16_t Y coordinate
w int16_t Width (pixels)
h int16_t Height (pixels)
data uint16_t* / uint8_t* Image data
transparent uint16_t Transparent color code
Note:
The color code is represented by 16 bits in total: 5 bits red, 6 bits green, top 5 bits blue

Example Usage:

See example sketch: M5Stack -> games -> Tetris

drawBmpFile()

Description:

Reads a bitmap from a file and draws it.

Syntax:

drawBmpFile(fs::FS &fs, const char *path, uint16_t x, uint16_t y)

Parameter Type Description
fs fs::FS File stream
path const char * File path (SD, SPIFFS)
x int16_t X coordinate
y int16_t Y coordinate
Note:
1. May not be able to scale depending on size and bit depth
2. Requires prior installation of Arduino ESP32 filesystem uploader

Example Usage:

#include "FS.h"
//#include "SPIFFS.h"
#include <M5Core2.h>
void setup(){
    M5.begin(true, false, false, false);
  M5.Lcd.drawBmpFile(SD, "/p2.bmp",0,0);
  //M5.Lcd.drawBmpFile(SPIFFS, "/p2.bmp", 0, 0);
}

We provide a script for converting jpg images to .c files, which can be used to convert some pictures and use the above API to draw the images on the screen bin2code.py

drawJpg()

Description:

Reads JPEG image data from memory and draws it.

Syntax:

void drawJpg(const uint8_t *jpg_data, size_t jpg_len, uint16_t x,uint16_t y, uint16_t maxWidth, uint16_t maxHeight,uint16_t offX, uint16_t offY, jpeg_div_t scale) {

Parameter Type Description
jpg_data uint8_t * Data start
jpg_len size_t Data length
x uint16_t X coordinate
y uint16_t Y coordinate
maxWidth

| uint16_t | Max width (pixels) | | maxHeight | uint16_t | Max height (pixels) | | offX | uint16_t | Offset X (pixels) | | offY | uint16_t | Offset Y (pixels) | | scale | jpeg_div_t | Scale |

Scale (jpeg_div_t):

Definition Function
JPEG_DIV_NONE None
JPEG_DIV_2 1/2
JPEG_DIV_4 1/4
JPEG_DIV_8 1/8
JPEG_DIV_MAX MAX
Note:
1. May not be able to scale depending on size, bit depth, and format (progressive, etc.)
2. tetris_img download

Example Usage:

#include <M5Core2.h>
extern uint8_t tetris_img[];    //Referencing an array storing the image, needs to be placed in the same folder as xxx.ino beforehand

void setup() {
  M5.begin();  //Initialize M5Core2
  M5.Lcd.drawJpg(tetris_img, 34215);    //Read the jpeg file named tetris_img from memory
}
void loop(){
}

drawJpgFile()

Description:

Reads JPEG data from a file stream and draws it.

Syntax:

void drawJpgFiledrawJpgFile(fs::FS &fs, const char *path, uint16_t x,uint16_t y,uint16_t maxWidth, uint16_t maxHeight, uint16_t offX,uint16_t offY, jpeg_div_t scale)

Parameter Type Description
fs fs::FS File stream
path const char * File path
x uint16_t X coordinate
y uint16_t Y coordinate
maxWidth uint16_t Max width (pixels)
maxHeight uint16_t Max height (pixels)
offX uint16_t Offset X (pixels)
offY uint16_t Offset Y (pixels)
scale jpeg_div_t Scale

Scale (jpeg_div_t):

Definition Function
JPEG_DIV_NONE no care
JPEG_DIV_2 1/2
JPEG_DIV_4 1/4
JPEG_DIV_8 1/8
JPEG_DIV_MAX MAX
Note:
May not be able to scale depending on size and format (progressive, etc.)

progressBar()

Description:

Displays a bar indicating progress.

Syntax:

void progressBar(int x, int y, int w, int h, uint8_t val)

Parameter Type Description
x int X coordinate
y int Y coordinate
w int Width (pixels)
h int Height (pixels)
val uint8_t Progress (0-100%)
Note:
The progress bar will be displayed in blue

Example Usage:

#include <M5Core2.h>

void setup() {
  M5.begin();  //Initialize M5Core2
  M5.Lcd.progressBar(0, 0, 240, 20, 20);    //Display a progress bar at (0,0) with width 240, height 20, and progress 20%
}

void loop() {
}

qrcode()

Description:

Creates a QR code.

Function Prototypes:

void qrcode(const char *string, uint16_t x, uint16_t y, uint8_t width, uint8_t version)

void qrcode(const String &string, uint16_t x, uint16_t y, uint8_t width, uint8_t version)

Parameter Type Description
val string / String& String to embed in QR
x uint16_t X coordinate
y uint16_t Y coordinate
width
 | uint8_t          | Width (pixels)         |

| version | uint8_t | QR code version |

Note:
Please choose the appropriate QR code version based on the number of characters

Example Usage:

#include <M5Core2.h>

void setup() {
  M5.Lcd.begin();   //Initialize M5Core2
  M5.Lcd.qrcode("http://www.m5stack.com", 50, 10, 220, 6);
}

void loop() {
}

Sprite

setColorDepth()

Description:

Sets the color depth.

Syntax:

void* TFT_eSprite::setColorDepth(int8_t b)

Example Usage:

#include <M5Core2.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
    img.setColorDepth(8); // Set color depth.  Set the color depth
    img.setTextSize(2);
    img.createSprite(320, 240);  //Create a 320x240 canvas. Create a 320x240 canvas
}

void loop() {}

The corresponding color depth should be set before creating the canvas.

createSprite()

Description:

Creates a canvas of specified width and height.

Syntax:

void createSprite(int16_t w, int16_t h, uint8_t frames)

Parameter Type Description
x int16_t X coordinate
y int16_t Y coordinate
frames uint8_t Color depth [1~2, optional]

Example Usage:

#include <M5Core2.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
  M5.begin();  //Initialize M5Core2
  img.createSprite(320, 240);   //Create a 320x240 canvas
  img.fillSprite(RED);  //Fill the canvas with red
  img.pushSprite(0, 0, WHITE);  //Push the canvas to screen at (0,0) with white as the transparent color
  M5.Lcd.print(img.height());   //Print the height of the canvas on screen
}

void loop() {}

fillSprite()

Description:

Fills the Sprite with a specified color.

Syntax:

void fillSprite(uint32_t color)

Parameter Type Description
color int32_t Filled color

Example Usage:

#include <M5Core2.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
  M5.begin();  //Initialize M5Core2
  img.createSprite(320, 240);   //Create a 320x240 canvas
  img.fillSprite(RED);  //Fill the canvas with red
  img.pushSprite(0, 0); //Push the canvas to screen at (0,0)
}

void loop() {}

pushSprite()

Description:

Pushes the canvas to a specified coordinate, setting a transparent color.

Syntax:

void pushSprite(int32_t x, int32_t y, uint16_t transparent)

Parameter Type Description
x int32_t X coordinate
y int32_t Y coordinate
transparent int16_t Transparent color (optional)

Example Usage:

#include <M5Core2.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
  M5.begin();  //Initialize M5Core2
  img.createSprite(320, 240);   //Create a 320x240 canvas
  img.fillSprite(RED);  //Fill the canvas with red
  img.fillCircle(100,100,20,GREEN);
  img.pushSprite(0, 0, GREEN);  //Push the canvas to screen at (0,0) with green as the transparent color
}

void loop() {}

height()

Description:

Returns the height of the Sprite.

Syntax:

int16_t height()

Example Usage:

#include <M5Core2.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
  M5.begin();  //Initialize M5Core2
  img.createSprite(320, 240);   //Create a 320x240 canvas
  img.fill

Sprite(RED);  //Fill the canvas with red
  img.pushSprite(0, 0, WHITE);  //Push the canvas to screen at (0,0) with white as the transparent color
  M5.Lcd.print(img.height());   //Print the canvas height on screen
}

void loop() {}

deleteSprite()

Description:

Deletes the canvas from memory.

Syntax:

void deleteSprite(void)

Example Usage:

#include <M5Core2.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
  M5.begin();  //Initialize M5Core2
  img.deleteSprite();   //Delete the canvas from memory
}

void loop() {}
Note:
LCD. img. both inherit from this file In_eSPI.h, and their usage is similar
On This Page