LCD turns white

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.

Have you tested your LCD with library example code?

Please run the library examples first. Study the code. e.g. from button_simple.ino

int pixel_x, pixel_y;     //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
    TSPoint p = ts.getPoint();
    pinMode(YP, OUTPUT);      //restore shared pins
    pinMode(XM, OUTPUT);
    digitalWrite(YP, HIGH);   //because TFT control pins
    digitalWrite(XM, HIGH);
    bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
    if (pressed) {
        pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
        pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
    }
    return pressed;
}

or from Touch_Shield_new.ino

void loop()
{
    uint16_t xpos, ypos;  //screen coordinates
    tp = ts.getPoint();   //tp.x, tp.y are ADC values

    // if sharing pins, you'll need to fix the directions of the touchscreen pins
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    // we have some minimum pressure we consider 'valid'
    // pressure of 0 means no pressing!

    if (tp.z > MINPRESSURE && tp.z < MAXPRESSURE) {
        ...

This is a "feature" of shared data pins. The TouchScreen.h library does not restore the pins after a ts.getPoint(); call.

David.

Thank you david, now it works!

Ive added:

    pinMode(YP, OUTPUT);      //restore shared pins
    pinMode(XM, OUTPUT);
    digitalWrite(YP, HIGH);   //because TFT control pins
    digitalWrite(XM, HIGH);

and it works.

You don't actually need the digitalWrite() statements.

Most versions of TouchScreen will leave YP, XM "high" even if they don't restore the pinMode()

David.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.