Issue with temp sensor loop with TFT function

Hello,

This is my first post on the forum and im glad to have found it!

I am trying to use my TFT to toggle a relay as well as read a temp sensor and update in real time. The updating of the temp sensor works fine when I omit the loop that gets a point from the TFT. When I activate the button part, it seems like the TSPoint p = ts.getPoint() function is screwing things up. The screen does not update, it just displays the first temp value that is seen by the sensor. However my button does function fine.

Any help on this would be greatly appreciated.

Cooling_manager_functions_working_auto_temp_no_click_10.5.2017.ino (4.35 KB)

OP’s code where we can see it.

//Libraries
#include <Adafruit_TFTLCD.h> 
#include <Adafruit_GFX.h>    
#include <TouchScreen.h>
#include <OneWire.h>
#include <DallasTemperature.h>

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

#define TS_MINX 893
#define TS_MINY 876
#define TS_MAXX 109
#define TS_MAXY 154

#define YP A3
#define XM A2
#define YM 9
#define XP 8

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

#define ONE_WIRE_BUS 52
#define SENSOR_INDEX 0 

const int intercooler_pump = 49;
int pump_on = 0;
const int power = 53;
float temp;
float oldtemp;
int button_state_change_1 = 0;

OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 364);
boolean buttonEnabled = true;
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  
pinMode(intercooler_pump, OUTPUT);
pinMode(power, OUTPUT);
digitalWrite(power, HIGH);
Serial.begin(9600);
sensors.begin();
startup(); //Display main menu
delay(3000);
main_menu();

 }

 
void loop() {
 
unsigned long currentMillis = millis();

 if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    oldtemp = temp;
    temp_sensor_1();
    temp_display();
    
  }



TSPoint p = ts.getPoint();


if(p.z > ts.pressureThreshhold){
p.x = map(p.x, TS_MAXX, TS_MINX, 0, 240);
p.y = map(p.y, TS_MAXY, TS_MINY, 0, 320);
if(p.x>50 && p.x<260 && p.y>180 && p.y<270 && buttonEnabled){
    
    buttonEnabled = true;
   pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
 
 button_state_change_1 = 1;
 if(pump_on == 0){
 pump_shutdown();}
 else {
  pump_powerup();
 }

}
}
else {
  return;
}

  }
  



void startup() {
  temp_sensor_1();
  delay(500);
  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  tft.setRotation(1);
  tft.fillScreen(BLACK);
  tft.drawRect(0,0,319,240,YELLOW);
  
  tft.setCursor(50,40);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("WXM Cooling Manager");
  
  tft.setCursor(50,80);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("Weapon X Motosports");
  


  //temp_sensor_1();
  Serial.print(temp); // Getting a random 185 on first power up of arduino, not sure why
  
}

void main_menu(){
  
  tft.fillScreen(BLACK);
  tft.drawRect(0,0,319,240,YELLOW);
  
  tft.setCursor(50,40);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("WXM Cooling Manager");
  
  tft.setCursor(50,80);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("Weapon X Motosports");
  

  
  tft.fillRect(50,160, 100, 40, GREEN);
  tft.drawRect(50,160,100,40,WHITE);
  tft.setCursor(80,190);
  tft.setTextColor(WHITE);
  tft.setTextSize(1.5);
  tft.print("Pump_on");
}

void pump_shutdown(){
  button_state_change_1 = 0;
  digitalWrite(intercooler_pump, HIGH);
  tft.fillRect(50,160, 100, 40, RED);
  tft.drawRect(50,160,100,40,WHITE);
  tft.setCursor(80,190);
  tft.setTextColor(WHITE);
  tft.setTextSize(1.5);
  tft.print("Pump_OFF ");
  pump_on = 1;
  return;
}

void pump_powerup(){
   button_state_change_1 = 0;
  digitalWrite(intercooler_pump, LOW);  
  tft.fillRect(50,160, 100, 40, GREEN);
  tft.drawRect(50,160,100,40,WHITE);
  tft.setCursor(80,190);
  tft.setTextColor(WHITE);
  tft.setTextSize(1.5);
  tft.print("Pump_ON ");
  pump_on = 0;
  return;
}
void temp_display(){

  tft.setCursor(90,120);
  tft.setTextColor(BLACK);
  tft.setTextSize(2);
  tft.print(oldtemp);
  
  tft.setCursor(90,120);
  tft.setTextColor(BLUE);
  tft.setTextSize(2);
  tft.print(temp);
   Serial.println();
  Serial.print(temp);
  Serial.println();
   Serial.println();
  Serial.print(oldtemp);
    Serial.println();
 
  
}
float temp_sensor_1() {
  
float temperatureInFahrenheit = sensors.getTempFByIndex(SENSOR_INDEX);
temp = temperatureInFahrenheit;
sensors.requestTemperatures(); // Send the command to get temperature readings 
//Serial.print(temp);
//delay(1000);
return temp;
}