mpaper_touch_paint.ino
Basic drawing application using the GT911 touch controller and e-Ink framebuffer.
Hardware: M5Paper with capacitive touch screen. Software: M5Paper.h. Execution: Touch screen to draw dots. Top-left corner acts as 'Clear' button. Note that e-Ink has refresh time, so drawing may appear choppy if update() is called too often.
mpaper_touch_paint.ino
#include <M5Paper.h>
void setup() {
M5.begin();
M5.display.clear();
M5.display.update();
Serial.begin(115200);
}
void loop() {
M5.update();
// Vérifier si un toucher est détecté
if (M5.TP.Touched()) {
uint16_t x = M5.TP.GetX();
uint16_t y = M5.TP.GetY();
// Dessiner un point noir
M5.display.drawPixel(x, y, BLACK);
// Pour un effet "crayon", dessiner aussi les points adjacents
M5.display.drawPixel(x + 1, y, BLACK);
M5.display.drawPixel(x, y + 1, BLACK);
M5.display.drawPixel(x - 1, y, BLACK);
M5.display.drawPixel(x, y - 1, BLACK);
// Mettre à jour l'écran (attention au clignotement e-Ink)
// On peut limiter la fréquence de mise à jour pour la performance
static uint32_t lastUpdate = 0;
if (millis() - lastUpdate > 100) {
M5.display.update();
lastUpdate = millis();
}
}
// Effacer l'écran si on touche le coin en haut à gauche
if (M5.TP.Touched() && M5.TP.GetX() < 50 && M5.TP.GetY() < 50) {
M5.display.clear();
M5.display.update();
delay(500);
}
}