Tab5 Touch related APIs and example.
#include <M5Unified.h>
#include <M5GFX.h>
m5::touch_detail_t touchDetail;
static int32_t w;
static int32_t h;
LGFX_Button button;
void setup() {
M5.begin();
w = M5.Lcd.width();
h = M5.Lcd.height();
M5.Lcd.fillScreen(WHITE);
M5.Display.setRotation(0);
M5.Display.setTextDatum(top_center);
M5.Display.drawString("Button Released", w / 2, 0, &fonts::FreeMonoBold24pt7b);
button.initButton(&M5.Lcd, w / 2, h / 2, 200, 200, TFT_BLUE, TFT_YELLOW, TFT_BLACK, "BTN", 4, 4);
button.drawButton();
}
void loop() {
M5.update();
touchDetail = M5.Touch.getDetail();
if (touchDetail.isPressed()) {
if(button.contains(touchDetail.x, touchDetail.y)){
M5.Display.drawString("Button Pressed", w / 2, 0, &fonts::FreeMonoBold24pt7b);
}
}
else {
M5.Display.drawString("Button Released", w / 2, 0, &fonts::FreeMonoBold24pt7b);
}
}
The program's function is: when a finger touches the screen, if the touch point is within the button area, it displays "Button Pressed"; otherwise, it displays "Button Released".
#include <M5Unified.h>
#include <M5GFX.h>
m5::touch_point_t touchPoint[5];//Tab5 supports up to 5-point touch
static bool drawed = false;
static int32_t w;
static int32_t h;
void setup() {
M5.begin();
w = M5.Lcd.width();
h = M5.Lcd.height();
M5.Lcd.fillScreen(WHITE);
M5.Display.setRotation(0);
M5.Display.setTextDatum(top_center);
M5.Display.drawString("Touch not found", w / 2, 0, &fonts::FreeMonoBold24pt7b);
M5.Display.setFont(&fonts::FreeMonoBold24pt7b);
}
void loop() {
M5.update();
int nums = M5.Lcd.getTouchRaw(touchPoint, 5);
if (nums)
{
M5.Display.drawString(" Touch detail: ", w / 2, 0, &fonts::FreeMonoBold24pt7b);
for (int i = 0; i < nums; i++)
{
M5.Display.setCursor(50, 160 + i * 48);
M5.Display.printf("Point %d X:%04d Y:%04d", i+1, touchPoint[i].x, touchPoint[i].y);
}
drawed = true;
}
else if (drawed){
drawed = false;
M5.Display.clear(WHITE);
M5.Display.drawString("Touch not found", w / 2, 0, &fonts::FreeMonoBold24pt7b);
}
vTaskDelay(1);
}
The program's function is: when a finger touches the screen, it displays the coordinates of the touch point. Tab5 supports up to 5-point touch.
The Touch of the Tab5 uses the Touch_Class
from the M5Unified
library. For more related APIs, refer to the documentation below: