pdf-icon

Arduino Quick Start

2. Devices & Examples

Tab5 Touch

Tab5 Touch related APIs and example.

Example

Compilation Requirements

  • M5Stack board manager version >= 3.2.0
  • Board selection = M5Tab5
  • M5Unified library version >= 0.2.7
  • M5GFX library version >= 0.2.8
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
#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".

The program only reads one touch point, and you can also develop the two-point touch function of Tab5 through the following API.

API

The Touch of the Tab5 uses the Touch_Class from the M5Unified library. For more related APIs, refer to the documentation below:

On This Page