<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[M5Stack is printing &#x27;touches&#x27; more than once on my M5 Paper]]></title><description><![CDATA[<p dir="auto">Hey so I currently got this code of a keypad I built, its still WIP but I'm trying to print out the number I press into the serial monitor. Now the problem comes, the printed number is correct but for whatever reasons it gets printed 3 times in total. I found out that when I touch and hold 1 number gets printed, but as soon as I let go 2 more numbers get printed.</p>
<p dir="auto"><strong>I really dont get why, tried everything</strong></p>
<pre><code>#include &lt;M5EPD.h&gt;

M5EPD_Canvas canvas(&amp;M5.EPD);

void setup() {
  M5.begin();
  M5.EPD.SetRotation(90);
  M5.TP.SetRotation(90);
  M5.EPD.Clear(true);
  canvas.createCanvas(540, 960);
  canvas.setTextSize(3);
  Serial.begin(115200);
}

void loop() {
  drawKeyboard();
  int playerId = getPlayerIdFromTouchscreen();
  Serial.println("Eingegebene Player ID: " + String(playerId));
  delay(2000); // Wartezeit, um die Ausgabe zu sehen
}

void drawKeyboard() {
  // Zeichne Tastatur
  M5.EPD.Clear(true);
  Serial.println("Geben Sie die Player ID ein:");

  M5EPD_Canvas canvas(&amp;M5.EPD);
  canvas.createCanvas(540, 960);
  canvas.setTextSize(3);

  // Zentriere die Tastatur
  int xOffset = 0;
  int yOffset = (canvas.height() - 720);

  // Buttons zeichnen
  for (int i = 0; i &lt; 3; i++) {
    for (int j = 0; j &lt; 3; j++) {
      int number = i * 3 + j + 1;
      canvas.fillRect(xOffset + j * 180, yOffset + i * 180, 179, 179, 0xFFFF);
      canvas.drawString(String(number), xOffset + j * 180 + 80, yOffset + i * 180 + 76);
    }
  }

  // 0 und OK Buttons zeichnen
  canvas.fillRect(xOffset + 360, yOffset + 540, 179, 179, 0xFFFF);
  canvas.fillRect(xOffset + 180, yOffset + 540, 179, 179, 0xFFFF);
  canvas.fillRect(xOffset, yOffset + 540, 179, 179, 0xFFFF);

  canvas.drawString("OK", xOffset + 432, yOffset + 620);
  canvas.drawString("0", xOffset + 262, yOffset + 620);
  canvas.drawString("DLT", xOffset + 60, yOffset + 620);

  canvas.pushCanvas(0, 0, UPDATE_MODE_GC16);
}

int getPlayerIdFromTouchscreen() {
  String inputDigits = "";
  bool inputDetected = false;  // Flagge, um mehrfache Erkennungen zu verhindern

  while (true) {
    M5.update();

    if (M5.TP.available() &amp;&amp; !M5.TP.isFingerUp()) {
      M5.TP.update();
      int touchX = M5.TP.readFinger(0).x;
      int touchY = M5.TP.readFinger(0).y;

      int xOffset = 0;
      int yOffset = (canvas.height() - 720);

      for (int i = 0; i &lt; 3; i++) {
        for (int j = 0; j &lt; 3; j++) {
          int buttonX = xOffset + j * 180;
          int buttonY = yOffset + i * 180;

          if (touchX &gt;= buttonX &amp;&amp; touchX &lt;= (buttonX + 179) &amp;&amp; touchY &gt;= buttonY &amp;&amp; touchY &lt;= (buttonY + 179)) {
            // Die Taste wurde berührt
            int number = i * 3 + j + 1;

            // Überprüfe, ob diese Taste bereits erkannt wurde
            if (!inputDetected) {
              // Setze die Flagge, um mehrfache Erkennungen zu verhindern
              inputDetected = true;

              // Serial-Ausgabe, um die gedrückte Taste anzuzeigen (optional)
              Serial.println("Gedrückte Taste: " + String(number));

              // Füge die Ziffer zur Zwischenvariable hinzu
              inputDigits += String(number);
            }
          }
        }
      }

      // Überprüfen, ob OK-Taste berührt wurde
      if (touchX &gt;= (xOffset + 360) &amp;&amp; touchX &lt;= (xOffset + 539) &amp;&amp; touchY &gt;= (yOffset + 540) &amp;&amp; touchY &lt;= (yOffset + 719)) {
        // Benutzereingabe beenden, wenn OK-Taste gedrückt wurde
        break;
      }
    }

    if (M5.TP.isFingerUp()) {
      // Wenn der Finger losgelassen wurde, setze die Flagge zurück
      inputDetected = false;
    }
  }

  Serial.println("Eingegebene Player ID: " + inputDigits); // Serial-Ausgabe am Ende

  return inputDigits.toInt(); // Konvertiere die Zeichenkette zu einer Ganzzahl
}
</code></pre>
]]></description><link>https://community.m5stack.com/topic/6041/m5stack-is-printing-touches-more-than-once-on-my-m5-paper</link><generator>RSS for Node</generator><lastBuildDate>Sat, 09 May 2026 11:03:11 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6041.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 01 Feb 2024 11:08:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to M5Stack is printing &#x27;touches&#x27; more than once on my M5 Paper on Fri, 02 Feb 2024 08:53:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ajb2k3" aria-label="Profile: ajb2k3">@<bdi>ajb2k3</bdi></a> yeah I fixed it. Currently fixing the delete button bcuz its shows the preivious number very subutle</p>
]]></description><link>https://community.m5stack.com/post/23589</link><guid isPermaLink="true">https://community.m5stack.com/post/23589</guid><dc:creator><![CDATA[bs811]]></dc:creator><pubDate>Fri, 02 Feb 2024 08:53:58 GMT</pubDate></item><item><title><![CDATA[Reply to M5Stack is printing &#x27;touches&#x27; more than once on my M5 Paper on Fri, 02 Feb 2024 08:09:47 GMT]]></title><description><![CDATA[<p dir="auto">You are probably seeing what is known as "Key Bounce" and need to look into "debouncing" the touch events.</p>
]]></description><link>https://community.m5stack.com/post/23588</link><guid isPermaLink="true">https://community.m5stack.com/post/23588</guid><dc:creator><![CDATA[ajb2k3]]></dc:creator><pubDate>Fri, 02 Feb 2024 08:09:47 GMT</pubDate></item></channel></rss>