Hi all,
I have a TFT-LCD Display with driver chip HX8347D. I am making a touch interface with four buttons (A), (B), (C) & (D) as shown below. My intention was to print a string of text on the LCD screen when a button is pressed.
The problem is that my TFT-LCD display cannot seem to draw anything while the touch function is being used. By comparing the code below with the output image above, it is clear that nothing prints after getting the point coordinates.
#include <Adafruit_GFX.h> // Hardware-specific library
#include <MCUFRIEND_kbv.h>
#include "TouchScreen.h"
#define MINPRESSURE 0
#define MAXPRESSURE 1023
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
MCUFRIEND_kbv tft;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, MINPRESSURE);
void setup() {
Serial.begin(115200);
int id = tft.readID();
tft.begin(id);
tft.setRotation(1);
tft.fillScreen(0);
tft.setTextSize(3);
tft.fillRoundRect(5,125,150,50,10,0x1F);
tft.fillRoundRect(5,185,150,50,10,0x3720);
tft.fillRoundRect(165,124,150,50,10,0xE800);
tft.fillRoundRect(165,185,150,50,10,0xF7C0);
tft.setTextColor(0xFFFF);
tft.setCursor(55,138);
tft.print("(A)");
tft.setCursor(215,138);
tft.print("(B)");
tft.setCursor(55,198);
tft.print("(C)");
tft.setCursor(215,198);
tft.print("(D)");
tft.setCursor(0,120);
}
int x_point = 0;
int y_point = 0;
void print_location() {
if (x_point > 169 && x_point < 220 && y_point > 25 && y_point < 115) {
Serial.println("You pressed (A)");
} else if (x_point > 169 && x_point < 220 && y_point > 120 && y_point < 215) {
Serial.println("You pressed (B)");
} else if (x_point > 240 && x_point < 285 && y_point > 25 && y_point < 115) {
Serial.println("You pressed (C)");
} else if (x_point > 240 && x_point < 285 && y_point > 120 && y_point < 215) {
Serial.println("You pressed (D)");
}
}
void loop() {
tft.setCursor(0,0);
tft.print("String 1"); // For testing only
TSPoint p = ts.getPoint();
tft.fillScreen(0x1F); // For testing only
if (p.z > MINPRESSURE) {
x_point = map(p.x, MINPRESSURE, MAXPRESSURE,0,320);
y_point = map(p.y, MINPRESSURE, MAXPRESSURE,0,240);
Serial.print(x_point);
Serial.print('\t');
Serial.println(y_point);
}
tft.setCursor(0,120);
tft.print("String 2"); // For testing only
}
If I change the minimum pressure and maximum pressure, the result stays the same. The touch function seems to work as expected since I was able to read the coordinates of the point touched from the serial monitor.
For additional info, my TFT-LCD display only works with the MCUFRIEND_kbv library. I have seen a similar example of a button interface working successfully from YouTube. I will appreciate any help provided. Thanks in advance.
