m5paper_it8951_touch_scroll-6.ino
Demonstrates capacitive touch interaction on the e-ink screen to scroll through textual content without refreshing the entire page at each step.
Uses the M5Paper library. The IT8951 driver handles partial updates to save power. The GT911 detects touch gestures. Ensure touch mode is enabled in M5.begin().
m5paper_it8951_touch_scroll-6.ino
#include <M5Paper.h>
// Définition des variables pour la gestion du défilement
int scrollOffset = 0;
const int lineHeight = 30;
const int totalLines = 20;
String displayText = "LIGNE 1\nLIGNE 2\nLIGNE 3\nLIGNE 4\nLIGNE 5\nLIGNE 6\nLIGNE 7\nLIGNE 8\nLIGNE 9\nLIGNE 10\nLIGNE 11\nLIGNE 12\nLIGNE 13\nLIGNE 14\nLIGNE 15\nLIGNE 16\nLIGNE 17\nLIGNE 18\nLIGNE 19\nLIGNE 20\nFIN";
void setup() {
M5.begin(true, false, true); // Init Serial, I2C (Touch), LED (non utilisé ici)
M5.Display.init();
M5.Display.setRotation(1); // Paysage
M5.Display.fillScreen(GREY);
drawScreen();
}
void loop() {
M5.update();
if (M5.Touch.changed()) {
TouchPoint_t pos = M5.Touch.getPressPoint();
// Défilement simple : touche gauche = haut, touche droite = bas
if (pos.x < M5.Display.width() / 2) {
scrollOffset = max(0, scrollOffset - lineHeight);
} else {
scrollOffset = min(totalLines * lineHeight, scrollOffset + lineHeight);
}
drawScreen();
M5.Display.update(); // Rafraîchissement partiel
}
delay(50);
}
void drawScreen() {
M5.Display.fillScreen(WHITE);
int y = 10 - scrollOffset;
int lineNum = 0;
// Affichage des lignes visibles
for (int i = 0; i < totalLines; i++) {
int currentY = y + i * lineHeight;
if (currentY > -lineHeight && currentY < M5.Display.height()) {
M5.Display.setCursor(10, currentY);
M5.Display.setTextColor(BLACK, WHITE);
M5.Display.print(String("Ligne ") + (i+1));
}
}
M5.Display.setTextColor(GREY);
M5.Display.setCursor(10, M5.Display.height() - 20);
M5.Display.print("Touchez Gauche/Droite pour defiler");
}