pdf-icon

TOUCH-GT911

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

begin()

Description:

Initializes the I2C bus.

Syntax:

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

available()

Description:

Whether new touch data is available for reading on the screen.

Syntax:

bool available()

update()

Description:

Refreshes screen detection.

Syntax:

void update()

SetRotation()

Description:

Sets the screen rotation angle, usually set to 90 degrees.

Syntax:

void SetRotation(uint16_t rotate)

readFingerX()

Description:

Reads the X coordinate of the touching finger.

Syntax:

uint16_t readFingerX(uint8_t num)

readFingerY()

Description:

Reads the Y coordinate of the touching finger.

Syntax:

uint16_t readFingerY(uint8_t num)

readFingerID()

Description:

Reads the ID coordinate of the touching finger.

Syntax:

uint16_t readFingerID(uint8_t num)

readFingerSize()

Description:

Reads the size of the rectangle area affected by the touching finger.

Syntax:

uint16_t readFingerSize(uint8_t num)

getFingerNum()

Description:

Reads the number of fingers touched last time.

Syntax:

uint8_t getFingerNum(void)

isFingerUp()

Description:

Checks if the finger is lifted up.

Syntax:

bool isFingerUp(void)

flush()

Description:

Clears the current touch status.

Syntax:

void flush(void)

readFinger()

Description:

Reads touch finger information, returns a structure instance.

Syntax:

tp_finger_t readFinger(uint8_t num)

Structure Instance:

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.available()){
        if(!M5.TP.isFingerUp()){
            M5.TP.update();
            canvas.fillCanvas(0);
            bool is_update = 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_update = 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_update)
            {
                canvas.pushCanvas(0,0,UPDATE_MODE_DU4);
            }
        }
    }
}
On This Page