TFT - Sensor conflict

Hi All,

I was unsure whether to post here or in programming because what I need is some guidance, but with what to write code for.

I will try to be clear as possible, but my lack of vocabulary on this subject usually prevents this.

I am building an aquarium controller with Mega, and I have run into a problem with my TFT LCD screen when running a DS18B20 Temp sensor. When I added the sensor to the project it caused a delay, or non-read, of a touch on the home screen. All other screens read the touch just fine.
My guess is that the Temerature Read in my loop is calculating and ticking away over and over so fast that the touch is not being read at the moment.

I have already tried running a delay in Temp function, and also in the loop, but it is not helping with the touch issue.

What do I need to do to clear up this issue? Do I need to write another function? Some type of debounce Boolean?

This video is from my journal, and may further illustrate what I’m trying to say.

Thanks for any guidance here!

SteveHi:
I have already tried running a delay in Temp function, and also in the loop, but it is not helping with the touch issue.

Delay is probably what's causing the problem, but nobody can tell what's wrong until you post your code. We're not mindreaders.

See…here’s where my lack of experience hinders me as I don’t know what section of code would be advisable to post, and I felt that posting the entire code thus far would be too much.

But, here it is…I don’t have any delays written into my code as of yet. I had to cut quite a bit in order to maintain the maximum allowed length, but hopefully left all the pertinent code.

//*******Included Libraries*******// 


#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>

//********    Declare Touch/LCD/RTC    **********
UTFTtf  myGLCD(ITDB32S, 38, 39, 40, 41);
ITDB02_Touch  myTouch(46,45,44,43,42);
RTC_DS1307 RTC;
 

//*******   Declare 1-Wire for TEMP sensors  ********
#define ONE_WIRE_BUS 6
#define TEMPERATURE_PRECISION 9
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature tempsensors(&oneWire);

float Tank_TempC;
float Tank_TempF;


   
    

//*******************************************      $Setup      ********************************[#SETUP]


void setup(){


  Wire.begin();
  RTC.begin();                                        //Initiate Real Time Clock
  


  tempsensors.begin();                                     //Begin Dallas 1-Wire Temperature
  pinMode(6, OUTPUT);
  if(!oneWire.search(tank_thermometer));
  
 // RTC.adjust(DateTime(__DATE__, __TIME__));            //Sets clock to current upload time
  
  Serial.begin(9600);
  boolean home_screen = true;
  Home_Screen();
}


/////////********************************** FUNCTIONS *******************************************//////////

 void Read_Temp(){
 
  tempsensors.requestTemperatures();
  Tank_TempC = tempsensors.getTempCByIndex(0);
  Tank_TempF = (((Tank_TempC * 9.0) / (5.0)) + 32.0);
  
}

 void Print_Temp(){
        if(home_screen == true){ 
       
       Read_Temp();
     
       myGLCD.setColor(0,255,255);
       myGLCD.setFont(Sinclair_M);
       
       myGLCD.print("F", 207, 21);
       myGLCD.printNumF(Tank_TempF, 1, 132, 21);
        }   
}


 ////////############ Home_Screen ###########///////
 /////Draws and adds functions of the homescreen////

 
 void Home_Screen(){
  
 //***** Draw Home_Screen *****
  myGLCD.loadBitmap(0,1,240,252, "HOMESC~1.raw");   //Homescreen Logo
  myGLCD.setColor(0,255,255);
  myGLCD.setFont(Sinclair_M);
  myGLCD.print("TEMP.:", 20, 21);
  myGLCD.print("pH  :", 35, 74);
  myGLCD.setColor(0,0,255);                         //sets button frame color to blue
  myGLCD.drawRoundRect(8,309,231,255);              //Draws Frame for clock read
  myGLCD.drawRoundRect(8,8,231,46);                 //Draws frame for temperature read
  myGLCD.drawRoundRect(8,62,231,100);               //Draws frame for pH read
  myGLCD.setColor(0,0,0);
  myGLCD.drawRoundRect(8,101,231,252);
  
 } 


//################### Touch Indication #################//
///## Indicates a button touch by drawing a RED frame ##//


void waitForIt(int x1, int y1, int x2, int y2)
{
  myGLCD.setColor(255,0,0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);


    while (myTouch.dataAvailable()){                            
      myTouch.read();
      x = myTouch.getX();
      y = myTouch.getY();
    }


  if ((home_screen == true) && (y <= 252) && (y >= 103)){
  myGLCD.setColor(0,0,0);                             //returns menu frame to black

  }
  else {
    myGLCD.setColor(0,0,255);                         //returns all other menu frames to blue
  }
}


//#################################### MAIN LOOP#######################################################//


void loop(){
    
//This code segment reads the current touch screen data (position pressed by the user) and stores the
//x value and the y value.

  if (myTouch.dataAvailable()){          //Get Curent Screen Data
    myTouch.read();
    x = myTouch.getX();
    y = myTouch.getY();
    Serial.print(x);
    Serial.print(" / ");
    Serial.println(y);
  }


//######################## CLOCK ##############################//

// This segment of code starts and draws Clock for all screens

  DateTime now = RTC.now();             //sets Datetime "now" to the current time
  Hours = now.hour();                 //Sets time varibles to Current RTC time
  Minutes = now.minute();
  Seconds = now.second();
  Day = now.day();
  Month = now.month();
  Year = now.year();
  Weekday = now.dayOfWeek(); 
  
  Draw_Clock(24, 252);
  

  //################ Navigation Touch Code ##############//
  //This code segment is for navigation from screen to screen
  
  if (home_screen == true){            //*****home screen begin***** 
     Print_Temp();                          //call to Print_Temps function
     
        if ((y >= 101) && (y <= 250)){         //menu button touch                              
         if ((x>=8) && (x<=231)){
          waitForIt(8, 101, 231, 250);
          x = 0;
          y = 0;

         Screen_select_false();
         menu_screen = true;
         Menu_Screen();
        }
      }
  
           if((y>=8) &&(y<=46)){               //Tenperature button touch
            if ((x>=8) && (x<=231)){
            waitForIt(8,8,231,46);
            x = 0;
            y = 0;
            
            Screen_select_false();
            temp_screen = true;
            TempHome_Screen();
            }
         }
            
        
            if((y>=62) &&(y<=100)){          //pH screen touch button from Home_Screen
            if ((x>=8) && (x<=231)){
            waitForIt(8,62,231,100);
            x = 0;
            y = 0;
            
            Screen_select_false();
            ph_screen = true;
            PH_Screen();
            }
          }                                   //******End Home Screen Touch********
        }    

          
 
 
 //************menu screen touch begin**************       

           if(home_screen == false){
           if (menu_screen == true){
             
        if ((y >= 179) && (y <= 243)){       //home return touch button
          if((x>=8) && (x<=93)){            
          waitForIt(29, 179, 93, 243);
          x = 0;
          y = 0;

         Screen_select_false();
         home_screen = true;
         Home_Screen();
     }
       
        }else if((y>=7) && (y<=71)){         //LED screen touch button
          if((x>=28) && (x<=92)){
            waitForIt(28,7,92,71);
            x=0;
            y=0;

           Screen_select_false();
           ledhome_screen = true;
           LEDhome_Screen();  
     } 
        
          if((y>=7) && (y<=71)){         //TEMP screen touch button
          if((x>=143) && (x<=208)){
            waitForIt(143,7,208,71);
            x=0;
            y=0;

           Screen_select_false();
           temp_screen = true;
           TempHome_Screen();        
     }
    }
        
        }else if((y>=91) && (y<=154)){         //PH screen touch button
          if((x>=144) && (x<=208)){
            waitForIt(144,91,208,154);
            x=0;
            y=0;

           Screen_select_false();
           ph_screen = true;
           PH_Screen();
       }
      }
     }
    

 //################## Home & Menu Return Code #########################################//    
          
           if(home_screen == false && menu_screen == false){
           if(ledchannel_screen == false && ledevents_screen == false){
             
           if ((y<=250) && (y>=214)){               //home screen return from pH/Temp/LED
           if((x>=161) && (x<=196)){
           waitForIt(161,250,196,214);
           x=0;
           y=0;
           
          Screen_select_false();
          home_screen = true;        
          Home_Screen();
        }
       }
            
           if ((y<=250) && (y>=216)){              //menu screen return from pH/Temp/LED screens
           if((x>=203) && (x<=238)){
           waitForIt(203,250,238,216);
           x=0;
           y=0;
           
          Screen_select_false();
          menu_screen = true;
          Menu_Screen();
        }
      } 
    }
  
//######################################################################################


//********************* LED Touch Begin ********************//        
           
          if (ledhome_screen == true){

           if((y<=206) && (y>=29)){
           if((x<=229) && (x>=138)){
             waitForIt(139,33,230,210);
             x=0;
             y=0;
             ledhome_screen = false;
             ledchannel_screen = true;
             LEDchannel_Screen();                   ///Color Channels Popup

           }
          } 
          
       } 
       else if (ledhome_screen == false){     //**********return to LEDmaster screen******
                    
           if((y<=213) && (y>=182)){ 
           if((x<=31) && (x>=2)){
             waitForIt(2,182,31,213);
             x=0;
             y=0;
             
             Screen_select_false();
             ledhome_screen = true;
             LEDhome_Screen();              //***********End Return to LEDmaster Screen***
             Print_Led_Brightness();  
           }
          } 
         }

Thanks for your time.