pdf-icon

Arduino Quick Start

2. Devices & Examples

Graphic Drawing

Line Drawing

drawArc

Function Prototype 1:

void drawArc(int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1)

Function Prototype 2:

void drawArc(int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1, const T &color)

Function Description:

  • Draws an arc, different values of r0 and r1 will create a thick arc.

Parameters:

  • x: Arc center point x coordinate
  • y: Arc center point y coordinate
  • r0: Inner circle radius
  • r1: Outer circle radius
  • angle0: Arc start angle
  • angle1: Arc end angle
  • color: Arc color (About Color Code)

Return:

  • null

drawBezier

Function Prototype 1:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color)

Function Prototype 2:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2)

Function Prototype 3:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, const T& color)

Function Prototype 4:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, const T& color)

Function Description:

  • Draws a Bezier curve, two types are available: 3-point type and 4-point type.

Parameters:

  • xN: Drawing point x coordinate
  • yN: Drawing point y coordinate
  • color: Curve color (About Color Code)

Return:

  • null

drawCircle

Function Prototype 1:

void drawCircle( int32_t x, int32_t y, int32_t r)

Function Prototype 2:

void drawCircle( int32_t x, int32_t y, int32_t r, const T& color)

Function Description:

  • Draws a circle

Parameters:

  • x: Circle center x coordinate
  • y: Circle center y coordinate
  • r: Circle radius
  • color: Circle color (About Color Code)

Return:

  • null

drawEllipse

Function Prototype 1:

void drawEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry)

Function Prototype 2:

void drawEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry, const T& color)

Function Description:

  • Draws an ellipse

Parameters:

  • x: Drawing center point x coordinate
  • y: Drawing center point y coordinate
  • rx: Ellipse major semi-axis
  • ry: Ellipse minor semi-axis
  • color: Ellipse color

Return:

  • null

drawEllipseArc

Function Prototype 1:

void drawEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1)

Function Prototype 2:

void drawEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1, const T& color)

Function Description:

  • Draw an elliptical arc, if r0 and r1 are different, a thick elliptical arc will be drawn.

Parameters:

  • x: x coordinate of the elliptical arc center
  • y: y coordinate of the elliptical arc center
  • r0x: inner ellipse x-radius
  • r0y: inner ellipse y-radius
  • r1x: outer ellipse x-radius
  • r1y: outer ellipse y-radius
  • angle0: starting angle
  • angle1: ending angle
  • color: elliptical arc color

Return:

  • null

drawFastHLine

Function Prototype 1:

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

Function Prototype 2:

void drawFastHLine( int32_t x, int32_t y, int32_t w, const T& color)

Function Description:

  • Draw a horizontal line

Parameters:

  • x: x coordinate of the starting point
  • y: y coordinate of the starting point
  • w: Line length
  • color: Line color

Return:

  • null

drawFastVLine

Function Prototype 1:

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

Function Prototype 2:

void drawFastVLine( int32_t x, int32_t y, int32_t w, const T& color)

Function Description:

  • Draw a vertical line

Parameters:

  • x: x coordinate of the starting point
  • y: y coordinate of the starting point
  • w: Line length
  • color: Line color

Return:

  • null

drawLine

Function Prototype 1:

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

Function Prototype 2:

void drawLine( int32_t x0, int32_t y0, int32_t x1, int32_t y1, const T& color)

Function Description:

  • Draw a straight line

Parameters:

  • x0: x coordinate of the starting point
  • y0: y coordinate of the starting point
  • x1: x coordinate of the ending point
  • y1: y coordinate of the ending point
  • color: Line color

Return:

  • null

drawGradientHLine

Function Prototype:

void drawGradientHLine( int32_t x, int32_t y, int32_t w, const T& colorstart, const T& colorend) 

Function Description:

  • Draw a horizontal gradient line

Parameters:

  • x: x coordinate of the starting point
  • y: y coordinate of the starting point
  • w: Line width
  • colorstart: Starting color
  • colorend: Ending color

Return:

  • null

drawGradientLine

Function Prototype:

void drawGradientLine ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, const T& colorstart, const T& colorend )

Function Description:

  • Draw a gradient line defined by two points

Parameters:

  • x0: x coordinate of the starting point
  • y0: y coordinate of the starting point
  • x1: x coordinate of the ending point
  • y1: y coordinate of the ending point
  • colorstart: Starting color
  • colorend: Ending color

Return:

  • null

drawGradientVLine

Function Prototype:

void drawGradientVLine( int32_t x, int32_t y, int32_t h, const T& colorstart, const T& colorend) 

Function Description:

  • Draw a vertical gradient line

Parameters:

  • x: x coordinate of the starting point
  • y: y coordinate of the starting point
  • h: Line height
  • colorstart: Starting color
  • colorend: Ending color

Return:

  • null

drawPixel

Function Prototype 1:

void drawPixel( int32_t x, int32_t y)

Function Prototype 2:

void drawPixel( int32_t x, int32_t y, const T& color)

Function Description:

  • Draw a pixel

Parameters:

  • x: x coordinate
  • y: y coordinate
  • color: pixel color

Return:

  • null

drawTriangle

Function Prototype 1:

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

Function Prototype 2:

void drawTriangle( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color)

Function Description:

  • Draw a triangle

Parameters:

  • xN: x coordinate of the triangle vertex
  • yN: y coordinate of the triangle vertex
  • color: triangle color

Return:

  • null

Filled Shapes

fillAffine

Function Prototype 1:

void fillAffine(const float matrix[6], int32_t w, int32_t h)

Function Prototype 2:

void fillAffine(const float matrix[6], int32_t w, int32_t h, const T& color)

Function Description:

  • Fill the affine transformation region

Parameters:

  • matrix: Affine transformation matrix
  • w: Graph width
  • h: Graph height
  • color: Fill color

Return:

  • null

fillArc

Function Prototype 1:

void fillArc( int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1)

Function Prototype 2:

void fillArc( int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1, const T& color)

Function Description:

  • Fill the arc region

Parameters:

  • x: x coordinate of the arc region center
  • y: y coordinate of the arc region center
  • r0: Inner radius
  • r1: Outer radius
  • angle0: starting angle
  • angle1: ending angle
  • color: Fill color

Return:

  • null

fillCircle

Function Prototype 1:

void fillCircle( int32_t x, int32_t y, int32_t r)

Function Prototype 2:

void fillCircle( int32_t x, int32_t y, int32_t r, const T& color)

Function Description:

  • Fill the circle region

Parameters:

  • x: Circle center x coordinate
  • y: Circle center y coordinate
  • r: Circle radius
  • color: Circle color (About Color Code)

Return:

  • null

fillEllipse

Function Prototype 1:

void fillEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry)

Function Prototype 2:

void fillEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry, const T& color)

Function Description:

  • Fill the ellipse region

Parameters:

  • x: Drawing center point x coordinate
  • y: Drawing center point y coordinate
  • rx: Ellipse major semi-axis
  • ry: Ellipse minor semi-axis
  • color: Ellipse color (About Color Code)

Return:

  • null

fillEllipseArc

Function Prototype 1:

void fillEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1)

Function Prototype 2:

void fillEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1, const T& color)

Function Description:

    • Draw a filled elliptical arc, if r0 and r1 are different, a thick elliptical arc will be drawn.

Parameters:

  • x: x coordinate of the elliptical arc center
  • y: y coordinate of the elliptical arc center
  • r0x: inner ellipse x-radius
  • r0y: inner ellipse y-radius
  • r1x: outer ellipse x-radius
  • r1y: outer ellipse y-radius
  • angle0: starting angle
  • angle1: ending angle
  • color: elliptical arc color

Return:

  • null

fillRect

Function Prototype 1:

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

Function Prototype 2:

void fillRect( int32_t x, int32_t y, int32_t w, int32_t h, const T& color)

Function Description:

  • Fill the rectangle region

Parameters:

  • x: Rectangle x coordinate of the starting point
  • y: Rectangle y coordinate of the starting point
  • w: Rectangle width
  • h: Rectangle height
  • color: Rectangle color (About Color Code)

Return:

  • null

fillRectAlpha

Function Prototype:

void fillRectAlpha(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t alpha, const T& color)

Function Description:

  • Draw a filled rectangle with transparency

Parameters:

  • x: Rectangle x coordinate of the starting point
  • y: Rectangle y coordinate of the starting point
  • w: Rectangle width
  • h: Rectangle height
  • alpha: Alpha (0-255)
  • color: Rectangle color (About Color Code)

Return:

  • null

fillRoundRect

Function Prototype 1:

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

Function Prototype 2:

void fillRoundRect( int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, const T& color)

Function Description:

  • Draw a rounded-corner filled rectangle

Parameters:

  • x: Rectangle x coordinate of the starting point
  • y: Rectangle y coordinate of the starting point
  • w: Rectangle width
  • h: Rectangle height
  • r: Corner radius
  • color: Rectangle color (About Color Code)

Return:

  • null

fillTriangle

Function Prototype 1:

void fillTriangle( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2)

Function Prototype 2:

void fillTriangle( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color)

Function Description:

  • Fill the triangle region

Parameters:

  • xN: x coordinate of the triangle vertex
  • yN: y coordinate of the triangle vertex
  • color: Triangle color (About Color Code)

Return:

  • null

floodFill

Function Prototype 1:

void floodFill( int32_t x, int32_t y)

Function Prototype 2:

void floodFill( int32_t x, int32_t y, const T& color)

Function Description:

  • Fill the approximate gamut range that corresponds to the specified coordinates

Parameters:

  • x: x coordinate of the specified point
  • y: y coordinate of the specified point
  • color: Fill color (About Color Code)

Return:

  • null

paint

Function Prototype 1:

void paint( int32_t x, int32_t y)

Function Prototype 2:

void paint( int32_t x, int32_t y, const T& color)

Function Description:

  • Draw the color at the specified position, same as the floodFill.

Parameters:

  • x: x coordinate of the specified position
  • y: y coordinate of the specified position
  • color: Color of the specified position

Return:

  • null

copyRect

Function Prototype:

void copyRect(uint32_t dst_x, uint32_t dst_y, uint32_t w, uint32_t h, uint32_t src_x, uint32_t src_y)

Function Description:

  • Copy rectangle region

Parameters:

  • dst_x: Copy destination x coordinate
  • dst_y: Copy destination y coordinate
  • w: Rectangle width
  • h: Rectangle height
  • src_x: Copy target x coordinate
  • src_y: Copy target y coordinate

Return:

  • null

Special Shapes

progressBar

Function Prototype:

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

Function Description:

  • Display a blue progress bar

Parameters:

  • x: Starting x coordinate of the progress bar
  • y: Starting y coordinate of the progress bar
  • w: Width of the progress bar
  • h: Height of the progress bar
  • val: Progress value (0 - 100)

Return:

  • null

qrcode

Function Prototype:

void qrcode(const char *string, uint16_t x = 50, uint16_t y = 10, uint8_t width = 220, uint8_t version = 6)
void qrcode(const String &string, uint16_t x = 50, uint16_t y = 10, uint8_t width = 220, uint8_t version = 6)

Function Description:

  • Generate a QR code from the specified string

Parameters:

  • string: String to generate the QR code from
  • x: Starting x coordinate of the QR code
  • y: Starting y coordinate of the QR code
  • width: Width of the QR code
  • version: QR code version (default is 6)

Return:

  • null

Example:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>

M5GFX display;

void setup() {
    display.begin();
    display.setRotation(3);
    display.clear(TFT_WHITE);
    delay(1000);
    uint16_t x = display.width() / 2;
    uint16_t y = display.height() / 2;

    display.drawArc(x, y, 100, 200, 0, 90, TFT_BLACK);
    display.drawBezier(0, 0, x/2, 0, x/2, y/2, TFT_VIOLET);
    display.drawBezier(0, 0, x/2, 0, x/2, y, 0, y, TFT_DARKGREEN);
    display.drawCircle(x, y, 200, TFT_BLACK);
    display.drawEllipse(x, y, 300, 200);
    display.drawEllipseArc(x, y, 100, 200, 200, 300, 180, 270);
    display.drawFastHLine(0, y/2, x);
    display.drawFastVLine(x/2, 0, y);
    display.drawLine(0, 0, x, y);
    display.drawGradientHLine(x, y/2*3, x, TFT_BLUE, TFT_RED);
    display.drawGradientVLine(x/2*3, y, y, TFT_BLUE, TFT_RED);
    display.drawGradientLine(x, y, x*2, y*2, TFT_BLUE, TFT_RED);
    display.drawTriangle(x/2, 0, x/4, y/2, x/2, y);

    static float Affine_mat[9] = {1, 0, 0,
                                  0, 1, y,
                                  0, 0, 1  };
    display.fillAffine(Affine_mat, x/4, y/4, TFT_RED);

    display.fillArc(x, y, 100, 200, 90, 180, TFT_ORANGE);
    display.fillCircle(x, y, 100, TFT_YELLOW);
    display.fillEllipse(x, y, 100, 50, TFT_BLACK);
    display.fillEllipseArc(x, y, 100, 200, 200, 300, 270, 360, TFT_SKYBLUE);
    display.fillRect(x/4, y, x/4, y/4, TFT_PINK);
    display.fillRectAlpha(x/4, y/4*5, x/4, y/4, 85, TFT_PINK);
    display.fillRoundRect(0, y/4*5, x/4, y/4, 30, TFT_GREEN);
    display.fillTriangle(0, 0, x/4, y/2, 0, y, TFT_BLUE);

    display.progressBar(x, 0, x, 40, 66);
    display.qrcode("Hello! This is M5Stack.", x/2*3, y/4, y/4*3);

    delay(2000);
    display.floodFill(x/4, y/2+10, TFT_MAGENTA);
    display.paint(x/4, y/2-10, TFT_CYAN);
}

void loop() {
}

write and read

getStartCount

Function Prototype:

uint32_t getStartCount(void)

Function Description:

  • Get the number of times the panel has called startWrite

Parameters:

  • null

Return:

  • uint32_t: Number of calls

readPixel

Function Prototype:

uint16_t readPixel(int32_t x, int32_t y)

Function Description:

  • Read the Color Code at the specified coordinates, Color Code format: RGB565

Parameters:

  • x: Specified x coordinate
  • y: Specified y coordinate

Return:

  • uint16_t: Readed Color Code

readPixelRGB

Function Prototype:

RGBColor readPixelRGB(int32_t x, int32_t y)

Function Description:

  • Read the Color Code at the specified coordinates, Color Code format: RGB888

Parameters:

  • x: Specified x coordinate
  • y: Specified y coordinate

Return:

  • RGBColor: Readed Color Code

readRect

Function Prototype:

void readRect( int32_t x, int32_t y, int32_t w, int32_t h, T* data)

Function Description:

  • Read the color data in the specified rectangle area

Parameters:

  • x: Specified x coordinate
  • y: Specified y coordinate
  • w: Specified width
  • h: Specified height
  • data: Buffer for storing the read color data

Return:

  • null

readRectRGB

Function Prototype:

void readRectRGB( int32_t x, int32_t y, int32_t w, int32_t h, RGBColor* data)

Function Description:

  • Read the color data in the specified rectangle area, Color Code format: RGB888

Parameters:

  • x: Specified x coordinate
  • y: Specified y coordinate
  • w: Specified width
  • h: Specified height
  • data: Buffer for storing the read color data

Return:

  • null

startWrite

Function Prototype:

void startWrite(bool transaction = true)

Function Description:

  • Declare CS (chip select signal) on the SPI bus. It works together with endWrite . Declaring startWrite allows M5GFX to make efficient use of the DMA buffer.
Note:
Cannot be used simultaneously with the SD card access function. When multiple drawing tasks exist, each must be controlled separately.

Parameters:

  • transaction: Transaction enable flag, default is true (enabled).

Return:

  • null

endWrite

Function Prototype:

void endWrite(void)

Function Description:

  • Close CS (chip select signal) on the SPI bus; used together with startWrite.

Parameters:

  • null

Return:

  • null
Note:
Following functionmust be used together with startWrite and endWrite.

pushBlock

Note:
Please refer to the M5GFX library data definitions for the difference between draw/push and write functions

Function Prototype:

void pushBlock( const T& color, uint32_t length)

Function Description:

Parameters:

  • color: Line color
  • length: Line length

Return:

  • null

pushPixels

Function Prototype 1:

void pushPixels(T* data, int32_t len )

Function Prototype 2:

void pushPixels(const uint16_t* data, int32_t len, bool swap)
void pushPixels(const void*     data, int32_t len, bool swap)

Function Description:

Parameters:

  • data: Pixels data
  • len: Data length
  • swap: Byte swap flag (optional)

Return:

  • null

pushPixelsDMA

Function Prototype 1:

void pushPixelsDMA(T* data, int32_t len )

Function Prototype 2:

void pushPixelsDMA(const uint16_t* data, int32_t len, bool swap)
void pushPixelsDMA(const void*     data, int32_t len, bool swap)

Function Description:

Parameters:

  • data: Pixels data
  • len: Data length
  • swap: Byte swap flag (optional)

Return:

  • null

writeColor

Function Prototype:

void writeColor( const T& color, uint32_t length)

Function Description:

Parameters:

  • color: Drawing color
  • length: Number of pixels drawn

Return:

  • null

writeFastHLine

Function Prototype 1:

void writeFastHLine( int32_t x, int32_t y, int32_t w)

Function Prototype 2:

void writeFastHLine( int32_t x, int32_t y, int32_t w, const T& color)

Function Description:

  • Draw a horizontal line

Parameters:

  • x: x coordinate of the starting point
  • y: y coordinate of the starting point
  • w: Line width
  • color: Line color

Return:

  • null

writeFastVLine

Function Prototype 1:

void writeFastVLine( int32_t x, int32_t y, int32_t w)

Function Prototype 2:

void writeFastVLine( int32_t x, int32_t y, int32_t w, const T& color)

Function Description:

  • Draw a certical line

Parameters:

  • x: x coordinate of the starting point
  • y: y coordinate of the starting point
  • w: Line width
  • color: Line color

Return:

  • null

writeFillRect

Function Prototype 1:

void writeFillRect( int32_t x, int32_t y, int32_t w, int32_t h)

Function Prototype 2:

void writeFillRect( int32_t x, int32_t y, int32_t w, int32_t h, const T& color)

Function Description:

  • Draw a filled rectangle

Parameters:

  • x: Rectangle x coordinate of the starting point
  • y: Rectangle y coordinate of the starting point
  • w: Rectangle width
  • h: Rectangle height
  • color: Rectangle color (About Color Code)

Return:

  • null

writeFillRectPreclipped

Function Prototype 1:

void writeFillRectPreclipped( int32_t x, int32_t y, int32_t w, int32_t h)

Function Prototype 2:

void writeFillRectPreclipped( int32_t x, int32_t y, int32_t w, int32_t h, const T& color)

Function Description:

  • Draw a pre-filled rectangle

Parameters:

  • x: Rectangle x coordinate of the starting point
  • y: Rectangle y coordinate of the starting point
  • w: Rectangle width
  • h: Rectangle height
  • color: Rectangle color (About Color Code)

Return:

  • null

writeIndexedPixels

Function Prototype:

void writeIndexedPixels(const uint8_t* data, T* palette, int32_t len, uint8_t depth = 8)

Function Description:

  • Draw image data using palette colors

Parameters:

  • data: Image data
  • paltte: Palette pointer
  • len: Image data length
  • depth: Color depth

Return:

  • null

writePixel

Function Prototype 1:

void writePixel(int32_t x, int32_t y)

Function Prototype 2:

void writePixel(int32_t x, int32_t y, const T& color)

Function Description:

  • Draw a pixel within the clipping region

Parameters:

  • x: Pixel x coordinate
  • y: Pixel y coordinate
  • color: Pixel color

Return:

  • null

writePixels

Function Prototype 1:

void writePixels(const T* data, int32_t len)

Function Prototype 2:

void writePixels(const uint16_t* data, int32_t len, bool swap)
void writePixels(const void*     data, int32_t len, bool swap)

Function Description:

  • Draw pixels within the clipping region; data will be drawn line by line, starting from the top-left corner.

Parameters:

  • data: Image data
  • len: Image data length
  • color: Pixels color
  • swap: Byte swap flag

Return:

  • null

writePixelsDMA

Function Prototype 1:

void writePixelsDMA(const T* data, int32_t len)

Function Prototype 2:

void writePixelsDMA(const uint16_t* data, int32_t len, bool swap)
void writePixelsDMA(const void*     data, int32_t len, bool swap)

Function Description:

  • Draw pixels using DMA within the clipping region; data will be drawn line by line, starting from the top-left corner.

Parameters:

  • data: Image data
  • len: Image data length
  • color: Pixels color
  • swap: Byte swap flag

Return:

  • null

Example:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>

M5GFX display;
const size_t data_len = 1320;
static uint16_t r_data;
RGBColor rgb_data;

void setup() {
    display.begin();
    display.setColorDepth(16);
    display.setRotation(1);
    display.clear(TFT_WHITE);
    display.setTextFont(&fonts::FreeSansOblique12pt7b);
    display.setTextColor(TFT_BLACK);
    delay(500);
    uint16_t x = display.width() / 2;
    uint16_t y = display.height() / 2;

    uint16_t w_data[data_len];
    for(int i=0; i<data_len; i++)
    {
        w_data[i] = 0;//BLACK
    }

    display.drawCenterString("Write Read Test", x, y);
    delay(1000);
    display.startWrite(true);
    display.writeFillRect(21, 21, 280, 10, TFT_RED);
    display.writeFillRectPreclipped(31, 31, 260, 10, TFT_BLUE);
    display.writeFastHLine(51, 51, 220, TFT_GREEN);
    display.writeFastHLine(51, 190, 220, TFT_GREEN);
    display.writeFastVLine(51, 51, 140, TFT_GREEN);
    display.writeFastVLine(270, 51, 140, TFT_GREEN);
    delay(500);
    for(int i=41; i<=280; i++)
    {
        for(int j=41; j<=50; j++)
        {
            display.writePixel(i, j, TFT_GREEN);
        }        
    }
    display.setWindow(51, 51, 270, 190);
    // By choosing to use the following code, you can clearly see the differences between setWindow and setAddrWindow.
    // display.setAddrWindow(51,51,270,190);
    display.pushBlock(TFT_ORANGE, data_len);
    display.writePixels(w_data, data_len, 0);//Has the same effect as the following code
    // display.pushPixels(w_data, data_len, 0);
    // display.writePixelsDMA(w_data, data_len, 0);
    delay(500);
    display.writeColor(TFT_DARKGREEN, data_len);//660 indicates that three rows of pixels have been drawn within the specified rectangular area.
    display.endWrite();

    auto color_565 = display.readPixel(21, 21);
    auto color_RGB = display.readPixelRGB(21, 21);
    display.setTextFont(&fonts::Font0);
    display.setCursor(21, 200);
    display.printf("565code: %#X, R:%d, G:%d, B:%d\n", color_565, color_RGB.r, color_RGB.g, color_RGB.b);

    display.readRect(25, 25, 1, 1, &r_data);
    display.readRectRGB(25, 25, 1, 1, &rgb_data);
    display.setCursor(21, 215);
    display.printf("888code: %#X\n", &r_data);
    display.setCursor(75, 230);
    display.printf("R:%d, G:%d, B:%d", &rgb_data.r, &rgb_data.g, &rgb_data.b);
}

void loop() {
}
On This Page