pdf-icon

Arduino Quick Start

2. Devices & Examples

PaperS3 Touch Screen

PaperS3 touch screen related APIs and example programs.

Example Program

Compilation Requirements

  • M5Stack Board Manager version >= 2.1.4
  • Board selection = M5PaperS3
  • M5Unified library version >= 0.2.5
  • M5GFX library version >= 0.2.7
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
#include <M5Unified.h>
#include <M5GFX.h>
m5::touch_detail_t touchDetail;
uint16_t color;
void setup() {
M5.begin();
M5.Display.setRotation(0);
M5.Display.setFont(&fonts::DejaVu40);
color = random(65535);
Serial.begin(115200);
Serial.println("Start drawing!");
M5.Display.print("Start drawing!");
}
void loop() {
M5.update();
touchDetail = M5.Touch.getDetail();
if (touchDetail.isPressed()) {
Serial.printf("x:%d, y:%d\r\n", touchDetail.x, touchDetail.y);
color = (color + 5) % 65536;
M5.Display.fillCircle(touchDetail.x, touchDetail.y, 15, color);
}
}

The main function of this program is to output the coordinates of the touch point to the computer via serial when a finger touches the screen, and draw circles with different grayscale colors at the touch point. The program reads only one touch point, but you can also use the APIs below to develop two-point touch functionality for the PaperS3.

API

The PaperS3 touch screen uses the Touch_Class from the M5Unified library. For more related APIs, please refer to the following documentation:

On This Page