Hello everyone.
I have problem with my LCD touchscreen shield turns white after I click button on it.
I am using Arduino Uno and 2.4" TFT LCD display with ILI9341 driver.
The code i am making is keypad with password, but not finished after this problem occur.
Code:
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
const int XP=8,XM=A2,YP=A3,YM=9;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
int x, y;
void setup() {
Serial.begin(9600);
uint16_t ID = tft.readID();
tft.begin(ID);
tft.setRotation(1);
tft.fillScreen(BLACK);
drawNumpad();
tft.setTextSize(3);
tft.setCursor(190, 14);
tft.setTextColor(WHITE);
}
void loop() {
TSPoint p = ts.getPoint();
if(p.z > MINPRESSURE && p.z < MAXPRESSURE) {
x = map(p.y, 74, 897, 0, 320);
y = map(p.x, 903, 127, 0, 240);
if(x >= 0 and x <= 60 and y >= 0 and y <= 60){
Serial.println("1");
tft.print("1");
}
if(x >= 60 and x <= 120 and y >= 0 and y <= 60){
Serial.println("2");
tft.print("2");
}
if(x >= 120 and x <= 180 and y >= 0 and y <= 60){
Serial.println("3");
tft.print("3");
}
if(x >= 0 and x <= 60 and y >= 60 and y <= 120){
Serial.println("4");
tft.print("4");
}
if(x >= 60 and x <= 120 and y >= 60 and y <= 120){
Serial.println("5");
tft.print("5");
}
if(x >= 120 and x <= 180 and y >= 60 and y <= 120){
Serial.println("6");
tft.print("6");
}
if(x >= 0 and x <= 60 and y >= 120 and y <= 180){
Serial.println("7");
tft.print("7");
}
if(x >= 60 and x <= 120 and y >= 120 and y <= 180){
Serial.println("8");
tft.print("8");
}
if(x >= 120 and x <= 180 and y >= 120 and y <= 180){
Serial.println("9");
tft.print("9");
}
if(x >= 0 and x <= 60 and y >= 180 and y <= 240){
Serial.println("*");
tft.print("*");
}
if(x >= 60 and x <= 120 and y >= 180 and y <= 240){
Serial.println("0");
tft.print("0");
}
if(x >= 120 and x <= 180 and y >= 180 and y <= 240){
Serial.println("#");
tft.print("#");
}
delay(500);
}
}
void drawNumpad(){
tft.fillRect(0, 0, 180, 240, BLUE);
tft.fillRect(0, 180, 60, 60, RED);
tft.fillRect(120, 180, 60, 60, RED);
tft.drawRect(0, 0, 60, 60, WHITE);
tft.drawRect(60, 0, 60, 60, WHITE);
tft.drawRect(120, 0, 60, 60, WHITE);
tft.drawRect(0, 60, 60, 60, WHITE);
tft.drawRect(60, 60, 60, 60, WHITE);
tft.drawRect(120, 60, 60, 60, WHITE);
tft.drawRect(0, 120, 60, 60, WHITE);
tft.drawRect(60, 120, 60, 60, WHITE);
tft.drawRect(120, 120, 60, 60, WHITE);
tft.drawRect(0, 180, 60, 60, WHITE);
tft.drawRect(60, 180, 60, 60, WHITE);
tft.drawRect(120, 180, 60, 60, WHITE);
tft.setTextColor(WHITE);
tft.setTextSize(4);
tft.setCursor(20, 14);
tft.println("1");
tft.setCursor(20, 74);
tft.println("4");
tft.setCursor(20, 134);
tft.println("7");
tft.setCursor(20, 194);
tft.println("*");
tft.setCursor(80, 14);
tft.println("2");
tft.setCursor(80, 74);
tft.println("5");
tft.setCursor(80, 134);
tft.println("8");
tft.setCursor(80, 194);
tft.println("0");
tft.setCursor(140, 14);
tft.println("3");
tft.setCursor(140, 74);
tft.println("6");
tft.setCursor(140, 134);
tft.println("9");
tft.setCursor(140, 194);
tft.println("#");
}
If something else will be needed then write down.