TOUCH-GT911

This is the M5Stack Paper touchscreen library.

In the M5.begin() initialization, the instance GT911 TP = GT911() has been created and initialized. You can use the API in this instance to get the touch interaction information.

begin()

Function:

Initialize the I2C bus

Syntax:

esp_err_t begin(uint8_t pin_sda, uint8_t pin_scl, uint8_t pin_int)

avaliable()

Function:

Whether there is new screen touch data to be read

Syntax:

bool avaliable()

update()

Function:

Refresh screen detection

Syntax:

void update()

SetRotation()

Function:

Set the screen rotation angle / usually set to 90°

Syntax:

void SetRotation(uint16_t rotate)

readFingerX()

Function:

Read the X coordinate of the touch finger

Syntax:

uint16_t readFingerX(uint8_t num)

readFingerY()

Function:

Read the Y coordinate of the touch finger

Syntax:

uint16_t readFingerY(uint8_t num)

readFingerID()

Function:

Read the ID coordinates of the touch finger

Syntax:

uint16_t readFingerID(uint8_t num)

readFingerSize()

Function:

Read the rectangle size of the touch finger's active area

Syntax:

uint16_t readFingerSize(uint8_t num)

getFingerNum()

Function:

Last read the number of touched fingers

Syntax:

uint8_t getFingerNum(void)

isFingerUp()

Function:

Detect whether the finger is lifted

Syntax:

bool isFingerUp(void)

flush()

Function:

Clear the current touch state

Syntax:

void flush(void)

readFinger()

Function:

Read the touch finger information and return to the structure instance

Syntax:

tp_finger_t readFinger(uint8_t num)

Structure:

typedef struct
{
    uint16_t x;
    uint16_t y;
    uint16_t id;
    uint16_t size;
}tp_finger_t;

Example:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);

int point[2][2];

void setup()
{
    M5.begin();
    M5.EPD.SetRotation(90);
    M5.TP.SetRotation(90);
    M5.EPD.Clear(true);
    canvas.createCanvas(540, 960);
    canvas.setTextSize(5);
    canvas.drawString("Touch The Screen!", 20, 400);
    canvas.pushCanvas(0,0,UPDATE_MODE_DU4);
}

void loop()
{

    if(M5.TP.avaliable()){
        if(!M5.TP.isFingerUp()){
            M5.TP.update();
            canvas.fillCanvas(0);
            bool is_upadte = false;
            for(int i=0;i<2; i++){
                tp_finger_t FingerItem = M5.TP.readFinger(i);
                if((point[i][0]!=FingerItem.x)||(point[i][1]!=FingerItem.y)){
                    is_upadte = true;
                    point[i][0] = FingerItem.x;
                    point[i][1] = FingerItem.y;
                    canvas.fillRect(FingerItem.x-50, FingerItem.y-50, 100, 100, 15);
                    Serial.printf("Finger ID:%d-->X: %d*C  Y: %d  Size: %d\r\n", FingerItem.id, FingerItem.x, FingerItem.y , FingerItem.size);
                }
            }
            if(is_upadte)
            {
                canvas.pushCanvas(0,0,UPDATE_MODE_DU4);
            }
        }
    }
}

On This Page