m5paper_touch_draw.ino

M5Paper IoT Development Kit with 4.7-inch Touchscreen e-Ink Display · File : m5paper_touch_draw.ino · Language : C++ (Arduino) · Use case : Afficher un message de bienvenue et dessiner un rectangle interactif via l'écran tactile e-Ink.

Initializes the e-Ink display and touch screen to display real-time coordinates.

Uses the M5EPD library. The screen is rotated 90 degrees. UPDATE_MODE_GC16 is used for sharp initial rendering, then GC16 or DU4 for touch updates. Compile with the 'M5Paper' board in Arduino IDE.

m5paper_touch_draw.ino

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);

void setup() {
  M5.begin();
  M5.EPD.SetRotation(90);
  M5.EPD.Clear(true); // Efface l'écran (mode rapide)
  
  canvas.createCanvas(540, 960);
  canvas.setTextSize(3);
  canvas.setCursor(10, 10);
  canvas.print("Hello M5Paper!");
  canvas.drawRect(10, 50, 100, 100, BLACK);
  
  canvas.pushCanvas(0, 0, UPDATE_MODE_GC16); // Rafraîchissement complet
}

void loop() {
  M5.update();
  if (M5.TP.Touched()) {
    int x = M5.TP.GetX();
    int y = M5.TP.GetY();
    
    canvas.clear();
    canvas.setCursor(10, 10);
    canvas.printf("X: %d, Y: %d", x, y);
    canvas.pushCanvas(0, 0, UPDATE_MODE_DU4); // Rafraîchissement partiel rapide
  }
}

← Back to the board