m5paper_touch_read.ino

M5Paper IoT Development Kit with 4.7-inch Touchscreen e-Ink Display · File : m5paper_touch_read.ino · Language : C++ · Use case : Lire les coordonnées tactiles capacitives GT911 et afficher un point sur l'écran e-Ink.

Demonstrates capacitive touch interaction on the e-Ink screen by drawing a dot where the user touches.

Uses the M5EPD library. The screen is set to 90-degree rotation. The loop checks touch state via M5.TP. Refresh uses UPDATE_MODE_DU4 for fast partial updates.

m5paper_touch_read.ino

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);

void setup() {
  M5.begin();
  M5.EPD.SetRotation(90);
  M5.EPD.Clear(true);
  canvas.createCanvas(480, 800); // Rotation 90 deg
  canvas.setTextSize(3);
  canvas.drawCentreString("Touch Screen", 240, 400, 4);
  canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
}

void loop() {
  M5.update();
  if (M5.TP.Touched()) {
    int x = M5.TP.readX();
    int y = M5.TP.readY();
    
    // Effacer l'ancienne position (simple exemple)
    canvas.drawCircle(240, 400, 20, G16_BLACK);
    canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
    
    // Dessiner un nouveau point
    canvas.drawCircle(x, y, 10, G16_BLACK);
    canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
    
    delay(200);
  }
}

← Back to the board