ILI9486 white screen after exactly 300 seconds

Hello everybody,
this is my first post here so please let me know if I am doing anything wrong or if I am not providing some key details.

I have a ILI9486 TFT LCD screen, bought here (this should be the wiki page).
I connected it to my original Arduino UNO using jumpers; I am quite certain the wiring is correct, but I skipped on connecting the SD card’s pins as I do not need the functionality yet. I have not used any resistor.

The sketch below reads the temperature and humidity using a DHT22 sensor and displays it on screen toghether with the current time (RTC DS3231 module for that). Because of the DHT sensor, the A4 and A5 pins of the I2C interface are connected to both the pins on the LCD screen and on the DHT22 sensor. In order to drive the LCD I am using the MCUFRIEND_kbv library, installed directly from Arduino IDE. I ran the configuration sketch included and assigned the necessary pins.

I am sorry if the code looks cluttered, but the main code is much more complicated and I tried to strip it of every unnecessary piece; I might have missed some stuff.
Anyway, the program runs correctly but after some time (usually about 2 minutes) the LCD screen just goes blank and displays a constant white image. I do not understand why. Also, the button and touch function is still working: if I put some debugging code, I can see on the serial monitor that the button can be pressed. However, no further commands are accepted by the screen.

#include <DS3232RTC.h> 
unsigned int timeH;
unsigned int timeM;
unsigned int timeS;

#include "DHT.h"
#define DHTPIN 10
#define DHTTYPE DHT22
float h;
float t;
bool ambCheck = true;

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 3000
const int XP = 8, XM = A2, YP = A3, YM = 9; //ID=0x9341
const int TS_LEFT = 141, TS_RT = 905, TS_TOP = 948, TS_BOT = 91;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 281);
Adafruit_GFX_Button btn_config, btn_home, btn_light, btn_lightA, btn_lightY, btn_lightN, btn_fanA, btn_fanY, btn_aP, btn_aM, btn_sP, btn_sM;
int pixel_x, pixel_y;     //Touch_getXY() updates global vars

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

int screenState = 0;
bool screenUpdate = true;

const int lightPin =  11;
bool lightState = false;
bool lightAuto = true;
int onH = 6;
int offH = 22;
const int fanPin =  12;
bool fanState = false;
bool fanAuto = true;

void setup() {
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  uint16_t ID = tft.readID();
  tft.setRotation(0);            //PORTRAIT
  pinMode(lightPin, OUTPUT);
  pinMode(fanPin, OUTPUT);

void loop() {
  timeH = hour();
  timeM = minute();
  timeS = second();
  digitalWrite(lightPin, lightState);

  if (timeS % 5 == 0 && ambCheck) {
    h = dht.readHumidity();
    t = dht.readTemperature();
    if (isnan(h) || isnan(t)) {
      Serial.println(F("Failed to read from DHT sensor!"));
    ambCheck = false;
  if (timeS % 5 == 1 && ambCheck == false)
    ambCheck = true;

  bool down = Touch_getXY();
  switch (screenState) {
    case 0:
      if (screenUpdate) {
        tft.fillRect(0, 370, 320, 110, BLUE);
        btn_config.initButtonUL(&tft, 0, 370, 320, 110, BLUE, BLUE, WHITE, "CONFIGURA", 4);
        screenUpdate = false;
      tft.setTextColor(WHITE, BLACK);
      timeWrite(timeH, timeM, timeS, 0);
      tWrite(t, 60);
      hWrite(h, 120);
    && btn_config.contains(pixel_x, pixel_y));
      if (btn_config.justPressed()) {
        //screenState = 1;
        screenUpdate = true;

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;

void timeWrite(int timeH,int timeM,int timeS,int y) {
  if (timeH < 10)
  if (timeM < 10)
  if (timeS < 10)

void tWrite(float t,int y) {

void hWrite(float h,int y) {

Does anybody have any idea of what I am doing wrong? Cheers and thanks for your time.

EDIT: after testing and using the millis() function I noticed this happens exactly after 300 seconds the program is running (300000 milliseconds). Why this?

Google "MCUFRIEND_kbv I2C"

Thank you, that was the solution. Really helpful, appreciate all your work! Sorry for the noob quuestion.