I recently bought a tft display with a touch panel built in but I cant seem to get the touchscreen part of it working. This is the link to the display www.amazon.co.uk/dp/B07PNQFSKN?ref=ppx_pop_mob_ap_share and this is my code (it does include code from other people)
#include <MCUFRIEND_kbv.h>
#include <Adafruit_GFX.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#include <FreeDefaultFonts.h>
const int XP=9,XM=A3,YP=A3,YM=8;
const int TS_LEFT=907,TS_RT=136,TS_TOP=942,TS_BOT=139;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
TSPoint tp;
#define BLACK 0x0000
#define NAVY 0x000F
#define DARKGREEN 0x03E0
#define DARKCYAN 0x03EF
#define MAROON 0x7800
#define PURPLE 0x780F
#define OLIVE 0x7BE0
#define LIGHTGREY 0xFFFF
#define DARKGREY 0x7BEF
#define BLUE 0x001F
#define GREEN 0x07E0
#define CYAN 0x07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFD20
#define GREENYELLOW 0xAFE5
void setup(void)
{
Serial.begin(9600);
uint16_t ID = tft.readID();
Serial.println(ID);
Serial.println(tft.width());
Serial.println(tft.height());
if (ID == 0xD3) ID = 0x9481;
tft.begin(ID);
tft.setRotation(0);
int h = 0;
int m = 0;
int s = 0;
tft.fillScreen(BLACK);
tft.setFont(&FreeSevenSegNumFont);
tft.setTextSize(1.5);
tft.setCursor(-15, 55);
tft.print("1234");
int r = 101;
int ws = 10;
while (ws != 0){
tft.drawFastHLine(0 , r , 320 , WHITE);
ws = ws - 1;
r = r + 1;
}
tft.drawRect(0, 112, 320, 380, BLUE);
tft.fillRect(0, 112, 320, 380, BLUE);
tft.drawRoundRect(22, 137, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(22, 137, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(97, 137, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(97, 137, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(172, 137, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(172, 137, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(247, 137, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(247, 137, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(22, 212, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(22, 212, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(97, 212, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(97, 212, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(172, 212, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(172, 212, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(247, 212, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(247, 212, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(22, 287, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(22, 287, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(97, 287, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(97, 287, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(172, 287, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(172, 287, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(247, 287, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(247, 287, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(97, 362, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(97, 362, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(247, 362, 50, 50, 10, LIGHTGREY);
tft.fillRoundRect(247, 362, 50, 50, 10, LIGHTGREY);
tft.drawRoundRect(25, 427, 272, 30, 10, LIGHTGREY);
tft.fillRoundRect(25, 427, 272, 30, 10, LIGHTGREY);
tft.setTextColor(0x2945);
tft.setFont(&FreeSevenSegNumFont);
tft.setTextSize(1.5);
tft.setCursor(20, 187);
tft.print("1");
tft.setCursor(105, 187);
tft.print("2");
tft.setCursor(180, 187);
tft.print("3");
tft.setFont(NULL);
tft.setTextSize(5);
tft.setCursor(257, 144);
tft.print("+");
tft.setFont(&FreeSevenSegNumFont);
tft.setTextSize(1.5);
tft.setCursor(28, 263);
tft.print("4");
tft.setCursor(105, 263);
tft.print("5");
tft.setCursor(180, 263);
tft.print("6");
tft.setFont(NULL);
tft.setTextSize(5);
tft.setCursor(259, 220);
tft.print("-");
tft.setFont(&FreeSevenSegNumFont);
tft.setTextSize(1.5);
tft.setCursor(28, 338);
tft.print("7");
tft.setCursor(105, 338);
tft.print("8");
tft.setCursor(180, 338);
tft.print("9");
tft.setFont(NULL);
tft.setTextSize(5);
tft.setCursor(259, 295);
tft.print("*");
tft.setFont(&FreeSevenSegNumFont);
tft.setTextSize(1.5);
tft.setCursor(106, 412);
tft.print("0");
tft.setFont(NULL);
tft.setTextSize(5);
tft.setCursor(258, 370);
tft.print("/");
tft.setCursor(80, 430);
tft.setFont(NULL);
tft.setTextSize(3.5);
tft.print("Calculate");
}
void loop(void)
{
tp = ts.getPoint();
int x = tp.x;
int y = tp.y;
if (tp.z > 24400){
Serial.println("x: " + String(x) + " y: " + String(y));
delay(10);
}
if (tp.z > 24400 and ((x < 72 and x > 22) and (y < 187 and y > 137))){
tft.fillScreen(RED);
delay(10);
}
}