Issues with TFT LCD Touchscreen and Arduino mega

I am fairly new to Arduino but we have recently decided to work on a project to automate our aquarium monitoring and quarantine water change processes.
As part of this I plan on using the 2.8" TFT LCD Shield along with an Arduino Mega2560 Board
I have been using the Adafruit libraries and have run through several examples that come with these libraries but now that I have moved on to trying to produce my own menu screens I am only seeing a blank white screen on uploading the sketch to the board
I am assuming there is a line of code I am missing which is needed to run the shield with the Mega board rather than an Uno but I have no idea what this is.

Any Suggestions would be greatly appreciated

Please post a link to the actual Display Shield that you have bought. e.g. Ebay sale page.

//load required libraries
#include "Adafruit_GFX.h"
#include "Adafruit_TFTLCD.h"
#include "TouchScreen.h"
#include <OneWire.h> 
#include <DallasTemperature.h>

//set touchscreen input pins
#define YP A3
#define XW A2
#define YW 9
#define XP 8

#define TS_MINX 100
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

TouchScreen ts = TouchScreen(XP, YP, XW, YW, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

#define MINPRESSURE 10
#define MAXPRESSURE 1000

//Set up TFT colours
#define BLACK 0x0000
#define BLUE tft.colour565(50, 50, 255);
#define DARKBLUE 0x0010
#define VIOLET 0x8888
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GREY tft.colour565(64, 64, 64);
#define GOLD 0xFEA0
#define BROWN 0xA145
#define SILVER 0xC618
#define LIME 0x07E0
#define PINK tft.colour565(255, 0, 255);

//Set temperature probe input
#define ONE_WIRE_BUS 22 
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

//Set varibles to run menu codes
int currentpage = 0; //0=homescreen, 1=waterchange menu, 2=temperature sensors.....

void setup()
{
// initialising touch screen display
tft.reset();
tft.begin(tft.readID());
Serial.begin(9600);
Serial.println();
Serial.print("reading id....0x");
delay(500);
Serial.println(tft.readID(), HEX);

tft.fillScreen(BLACK); //fill screen with colour
tft.setRotation(1); //horizontal orientation
tft.setTextSize(3); //set size of font
tft.setTextColor(WHITE); //set colour of text

Serial.println("Dallas Temperature IC Control Library Demo");
 sensors.begin();
}
//Draw menu screen
void drawHome()
{
  tft.fillScreen(BLACK);
  tft.fillRoundRect(60, 180, 200, 40, 8, RED); // sensor menu
  tft.fillRoundRect(60, 130, 200, 40, 8, RED); //waterchange menu
  tft.setCursor(60, 20);
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(BLACK);
  tft.setCursor(65, 195);
  tft.print("   Monitoring");
  tft.setCursor(105, 145);
  tft.print("   Waterchange");
  delay(500);
}
// Draw Waterchange Menu
void drawWC()
 tft.fillScreen(BLACK);
  tft.fillRoundRect(60, 100, 100, 40, 8, BLUE); // WC 10%
  tft.setCursor(20, 20);
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(WHITE);
  tft.setCursor(65, 115);
  tft.print("  WC 10%");
  tft.fillRoundRect(60, 150, 100, 40, 8, BLUE); // WC 20%
  tft.setCursor(20, 20);
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(WHITE);
  tft.setCursor(65, 165);
  tft.print("  WC 20%");
   tft.fillRoundRect(60, 200, 100, 40, 8, BLUE); // WC 50%
  tft.setCursor(20, 20);
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(WHITE);
  tft.setCursor(65, 215);
  tft.print("  WC 50%");
  tft.fillRoundRect(180, 100, 100, 40, 8, DARKBLUE); // Top up
  tft.setCursor(20, 20);
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(WHITE);
  tft.setCursor(185, 115);
  tft.print("  Top-up");
  tft.fillRoundRect(180, 150, 100, 40, 8, DARKBLUE); // Drain
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(WHITE);
  tft.setCursor(185, 165);
  tft.print("  Drain");
  tft.fillRoundRect(870, 900, 50, 30, 8, RED); //Return Button
  tft.setCursor(885, 915);
  tft.setTextColor(BLACK);
  tft.print("<-");
  delay(300);
{
//Draw water monitoring menu
void drawMonitor(); 
tft.fillScreen(BLACK);
  tft.fillRoundRect(60, 60, 50, 200, 8, BLUE); // Q1
  tft.setCursor(20, 20);
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(WHITE);
  tft.setCursor(65, 115);
  tft.print("  Q1");
   tft.fillRoundRect(120, 60, 50, 200, 8, BLUE); // Q2
  tft.setCursor(20, 20);
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(WHITE);
  tft.setCursor(125, 115);
  tft.print("  Q2");
   tft.fillRoundRect(180, 60, 50, 200, 8, BLUE); // Q3
  tft.setCursor(20, 20);
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(WHITE);
  tft.setCursor(185, 115);
  tft.print("  Q3");
   tft.fillRoundRect(240, 60, 50, 200, 8, BLUE); // Q4
  tft.setCursor(20, 20);
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(WHITE);
  tft.setCursor(245, 115);
  tft.print("  Q4");
  tft.fillRoundRect(870, 900, 50, 30, 8, RED); //Return Button
  tft.setCursor(885, 915);
  tft.setTextColor(BLACK);
  tft.print("<-");
  delay(300);
}
void loop()
{
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint(); //read touchscreen coordinates
  digitalWrite(13, LOW);

  pinMode(XW, OUTPUT);
  pinMode(YP, OUTPUT);

  if (currentpage == 0)
  {
    if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
    {
      if (p.x > 563 && p.x < 683 && p.y > 275 && p.y < 750) // check if waterchange menu button is pressed
      {
        Serial.println("Waterchange Menu Selected");
        tft.fillRoundRect(60, 130, 200, 40, 8, WHITE);
        delay(100);
        tft.fillRoundRect(60, 130, 200, 40, 8, RED);
        currentpage = 1; //run waterchange menu code
        drawWC(); //open waterchange menu
      }
      if (p.x > 736 && p.x < 855 && p.y > 255 && p.y < 725) // check if monitoring button is pressed
      {
        Serial.println("Water Sensing");
        tft.fillRoundRect(60, 180, 200, 40, 8, WHITE); 
        delay(100);
        tft.fillRoundRect(60, 180, 200, 40, 8, RED); 
        currentpage = 2; //run water monitoring menu code
        drawMonitor(); //open water monitoring menu
      }
    }
  }
  if currentpage == 1 //waterchange menu
  {
    
  }
  if currentpage == 2 // water monitoring menu code
  {
    while (currentpage==2) 
     // call sensors.requestTemperatures() to issue a global temperature 
 // request to all devices on the bus 
/********************************************************************/
 sensors.requestTemperatures(); // Send the command to get temperature readings 
/********************************************************************/
 float TQ1 =  (sensors.getTempCByIndex(0)); // set up variable to read temperature of tank Q1
   tft.setCursor(65,135);
   tft.print(TQ1);
   delay(10000); 
  
  }
}

image

I pretty sure (not 100%) this is the product page that it was purchased from

You have a regular "Mcufriend-style Uno Shield"
You have used pinMode() correctly after calling

ts.getPoint(); 

So the only obvious problem is

Adafruit_TFTLCD.h supports several different TFT controllers but perhaps it does not know your particular ID.

I suggest that you run all the library examples that come with Adafruit_TFTLCD

If your ID is not supported, install MCUFRIEND_kbv via the IDE Library Manager. It supports many more IDs.

David.

Thanks I think I am now having more success with the MCUFRIEND library
I am currently trying to make buttons that will allow selection of different menu screens (basically a main menu that will make it easier to select the correct function) I have been using the simple button example from the library as a template to build on but I am unsure as to how to make this select different screens and then allow the buttons on those new screens to function

//load required libraries
#include "Adafruit_GFX.h"
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include "TouchScreen.h"
#include <OneWire.h> 
#include <DallasTemperature.h>

//set touchscreen input pins


#define MINPRESSURE 10
#define MAXPRESSURE 1000

// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341
const int TS_LEFT = 75, TS_RT = 905, TS_TOP = 99, TS_BOT = 921;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

Adafruit_GFX_Button sensor, WC, WC_WC10, WC_WC20, WC_WC50, WC_Top, WC_Return; //list of buttons

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;
}
//Set up TFT colours
#define BLACK 0x0000
#define BLUE 0x001F
#define DARKBLUE 0x0010
#define VIOLET 0x8888
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GOLD 0xFEA0
#define BROWN 0xA145
#define SILVER 0xC618
#define LIME 0x07E0


//Set temperature probe input
#define ONE_WIRE_BUS 22 
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

//Set varibles to run menu codes
int currentpage = 0; //0=homescreen, 1=waterchange menu, 2=temperature sensors.....

void setup()//////////////////
{
// initialising touch screen display
tft.reset();
tft.begin(tft.readID());
Serial.begin(9600);
Serial.println();
Serial.print("reading id....0x");
delay(500);
Serial.println(tft.readID(), HEX);

tft.fillScreen(BLACK); //fill screen with colour
tft.setRotation(0); //horizontal orientation
tft.setTextSize(3); //set size of font
tft.setTextColor(WHITE); //set colour of text

Serial.println("Dallas Temperature IC Control Library Demo");
 sensors.begin();
}
//Draw menu screen
void drawHome()
{
  tft.fillScreen(BLACK);
  tft.fillRect(40, 80, 160, 80, BLUE);// Menu header (start X, start Y, Length, Height
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(WHITE);
  tft.setCursor(70, 120);
  tft.print("  QA Manager");
  sensor.initButton(&tft,  60, 200, 100, 40, CYAN, CYAN, BLACK, "Temp", 2); // sensor menu
  WC.initButton(&tft, 180, 200, 100, 40, CYAN, CYAN, BLACK, "Manage", 2); //waterchange menu
  Adafruit_GFX_Button *buttons[] = {&sensor, &WC, NULL};
  bool update_button(Adafruit_GFX_Button *b, bool down)
{
    b->press(down && b->contains(pixel_x, pixel_y));
    if (b->justReleased())
        b->drawButton(false);
    if (b->justPressed())
        b->drawButton(true);
    return down;
}

/* most screens have different sets of buttons
 * life is easier if you process whole list in one go
 */
bool update_button_list(Adafruit_GFX_Button **pb)
{
    bool down = Touch_getXY();
    for (int i = 0 ; pb[i] != NULL; i++) {
        update_button(pb[i], down);
    }
    return down;
}
}

void drawWC()
{
 tft.fillScreen(BLACK);
 tft.fillRect(25, 30, 190, 80, BLUE, WHITE, "Water Changes", 2);// Menu header (start X, start Y, Length, Height
  tft.setTextSize(2);
  tft.setFont();
  tft.setTextColor(WHITE);
  tft.setCursor(50, 55);
  tft.print("Water Changes");
  WC_WC10.initButton(&tft,  60, 140, 100, 40, CYAN, CYAN, BLACK, "WC 10%", 2);
  WC_WC20.initButton(&tft,  60, 190, 100, 40, CYAN, CYAN, BLACK, "WC 20%", 2);
  WC_WC50.initButton(&tft,  60, 240, 100, 40, CYAN, CYAN, BLACK, "WC 50%", 2);
  WC_Top.initButton(&tft,  180, 140, 100, 40, CYAN, CYAN, BLACK, "Top Up", 2);
  WC_Return.initButton(&tft,  180, 240, 100, 40, RED, Red, BLACK, "Back", 2);
  Adafruit_GFX_Button *buttons[] = {&WC_WC10, &WC_WC20, &WC_WC50, &WC_Top, &WC_Return, NULL};
  delay(300);
  bool update_button(Adafruit_GFX_Button *b, bool down)
{
    b->press(down && b->contains(pixel_x, pixel_y));
    if (b->justReleased())
        b->drawButton(false);
    if (b->justPressed())
        b->drawButton(true);
    return down;
}
}
void loop(void)

    }
    if (WC.justPressed()) {
        currentpage==1;
         drawWC(); //open waterchange menu
    }
}
}

}

Does anyone have any advice