I am using the IDE 2.2.1 to program an M5Paper device, which basically an ESP32 with an E-Ink display that is a GT911 capacitive touch screen.
I am playing with the touch screen and although I got it working and stopped the finger cordinates being repeated many times per touch, they still repeat twice per touch. I think what is happening is that the coordinates are given once for touch and once for "fingerUp". How can I limit this to a single set of coordinates?
Here is the serial output:
M5EPD initializing...OK
Box 1 - X Coordinate: 20, Y Coordinate: 100
Box 2 - X Coordinate: 20, Y Coordinate: 200
Box 3 - X Coordinate: 20, Y Coordinate: 300
Box 4 - X Coordinate: 20, Y Coordinate: 400
0....0
0....0
0....0
326....582
326....582
326....582
16....427
BOX 4
Cabbage 16....427
BOX 4
Cabbage
And here is the code:
#include <M5EPD.h>
M5EPD_Canvas canvas(&M5.EPD);
struct coords {
String veg;
int x;
int y;
};
bool fill = false;
// Define the number of boxes you want plus one
const int numBoxes = 5;
// Create an array of Coordinates structs
coords box[numBoxes];
void makeBoxes() {
for (int i = 1; i < numBoxes; i++) {
box[i].x = 20;
box[i].y = i * 100;
}
box[1].veg = "Potato ";
box[2].veg = "Broccolli";
box[3].veg = "Turnip ";
box[4].veg = "Cabbage ";
// Print the coordinates for each box
for (int i = 1; i < numBoxes; i++) {
Serial.print("Box ");
Serial.print(i);
Serial.print(" - X Coordinate: ");
Serial.print(box[i].x);
Serial.print(", Y Coordinate: ");
Serial.println(box[i].y);
//Draw each box
canvas.drawRect(box[i].x, box[i].y, 50, 50, 15);
canvas.drawString(box[i].veg, 100, box[i].y);
}
/* // Accessing specific box coordinates
int boxIndex = 2;
Serial.print("Box ");
Serial.print(boxIndex);
Serial.print(" - X Coordinate: ");
Serial.print(box[boxIndex].x);
Serial.print(", Y Coordinate: ");
Serial.println(box[boxIndex].y);*/
}
void setup() {
M5.begin();
M5.EPD.SetRotation(90);
M5.TP.SetRotation(90);
M5.EPD.Clear(true);
canvas.createCanvas(540, 960);
canvas.setTextSize(4);
canvas.drawString("Select a vegatable", 20, 20);
makeBoxes();
canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
}
void loop() {
int col;
if (M5.TP.available()) {
if (!M5.TP.isFingerUp()) {
M5.TP.update();
} else {
tp_finger_t FingerItem = M5.TP.readFinger(0);
int x = FingerItem.x;
int y = FingerItem.y;
M5.TP.update();
Serial.print(x);
Serial.print("....");
Serial.println(y);
for (int i = 1; i < numBoxes; i++) {
if ((y >= box[i].y) && (y <= box[i].y + 50)) {
Serial.print("BOX ");
Serial.println(i);
canvas.fillRect(20, box[i].y, 50, 50, 15);
Serial.print(box[i].veg);
canvas.drawString(box[i].veg, 20, 800);
canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
}
}
}
}
}