3,5" TFT touch Screen + SD card slot MCU_friend.com... NEW Short Help topic!

I got a new problem now with the TFT_HX8357.h

Screen is flashing / refreshing with the delay time..

Any hints to fix it?

The code i use:

#include <DHT.h>
#include <TFT_HX8357.h> // Hardware-specific library
#include "Free_Fonts.h" // Include the header file attached to this sketch


#define DHTPIN 13               //pin for DHT22
#define DHTTYPE DHT22   // DHT 22  (AM2302)

#define SensorPin A9            
#define Offset 0.40            //deviation compensate
#define samplingInterval 20
#define printInterval 800
#define ArrayLenth  40    //times of collection
int pArray[ArrayLenth];   
int pArrayIndex=0;    



DHT dht(DHTPIN, DHTTYPE);



TFT_HX8357 tft = TFT_HX8357();       // Invoke custom library

unsigned long drawTime = 0;


void setup()
{

  
  Serial.begin(9600);
  
  tft.begin();
  tft.setRotation(1);
  
  dht.begin();

  analogReference(INTERNAL1V1);
  
}

void loop() {

  pLoop();
  dthLoop();
  displayLoop();

}

void displayLoop()
{
  
  int xpos =  0;
  int ypos = 40;  
  
  tft.setTextColor(TFT_WHITE, TFT_BLACK);
  
    tft.setFreeFont(FSB18);
   tft.fillScreen(TFT_BLACK);

   
tft.drawString("VEDEN LAMPOTILA", 1, 90, GFXFF);
tft.drawString("ILMAN LAMPOTILA", 1, 150, GFXFF);
tft.drawString("C", 420, 150, GFXFF);
tft.drawString("ILMAN KOSTEUS", 1, 230, GFXFF);
tft.drawString("%", 420, 230, GFXFF);
tft.drawString(" ARVO", 1, 10, GFXFF);

}

void dthLoop()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  
    tft.setFreeFont(FSB18);
   
 
tft.drawFloat(t, 1, 370, 150, GFXFF);
tft.drawFloat(h, 1, 370, 230, GFXFF);
  
  delay (5000);

}


 void phLoop ()
{
  static unsigned long samplingTime = millis();
  static unsigned long printTime = millis();
  static float pHValue,voltage;
  if(millis()-samplingTime > samplingInterval)
  {
      pArray[pHArrayIndex++]=analogRead(SensorPin);
      if(pArrayIndex==ArrayLenth)pHArrayIndex=0;
      voltage = avergearray(pHArray, ArrayLenth)*5.0/1024;
      pValue = 3.50*voltage+Offset;
      samplingTime=millis();
  }
  if(millis() - printTime > printInterval)   //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
  {
    Serial.print("Voltage:");
        Serial.print(voltage,2);
        Serial.print("    pH value: ");
    Serial.println(pValue,2);
  }
  {
    
 tft.setFreeFont(FSB18);

  tft.drawFloat(pValue, 1, 300, 10, GFXFF);
        printTime=millis();
  }
}
double avergearray(int* arr, int number){
  int i;
  int max,min;
  double avg;
  long amount=0;
  if(number<=0){
    Serial.println("Error number for the array to avraging!/n");
    return 0;
  }
  if(number<5){   //less than 5, calculated directly statistics
    for(i=0;i<number;i++){
      amount+=arr[i];
    }
    avg = amount/number;
    return avg;
  }else{
    if(arr[0]<arr[1]){
      min = arr[0];max=arr[1];
    }
    else{
      min=arr[1];max=arr[0];
    }
    for(i=2;i<number;i++){
      if(arr[i]<min){
        amount+=min;        //arr<min
        min=arr[i];
      }else {
        if(arr[i]>max){
          amount+=max;    //arr>max
          max=arr[i];
        }else{
          amount+=arr[i]; //min<=arr<=max
        }
      }//if
    }//for
    avg = (double)amount/(number-2);
  }//if
  return avg;

}
  
 

  }