'temp1' was not declared in this scope

i am trying to make a water cooling controller for my PC. so far everything works fine, but:
everytime i try to print the temperature on the LCD i get the mentioned error. but if i leave it only in the serial monitor it works. tried different changes but could not find the right solution.
everything else is fine, just trying to get the temp1 and temp2 printed to lcd does not work.

Arduino MEGA,

//Temperatursensor
#include <OneWire.h>
#include <DallasTemperature.h>
 
OneWire  ds(17); //pin für ds1820
 
//DeviceAdressen der einzelnen ds1820 Temperatursensoren angeben. (loop anpassen)
DeviceAddress sensor1 = { 0x28, 0x70, 0x42, 0x8, 0x0, 0x0, 0x80, 0x7C };
DeviceAddress sensor2 = { 0x28, 0xFF, 0xC2, 0xA7, 0x74, 0x16, 0x4, 0x90 }; //Knoten
//DeviceAddress sensor3 = { 0x10, 0x11, 0x40, 0xC0, 0x1, 0x8, 0x0, 0x9A };
//DeviceAddress sensor4 = { 0x10, 0x77, 0x38, 0x57, 0x2, 0x8, 0x0, 0x3B };
 
char sensor1Name[] = "CPU: ";
char sensor2Name[] = "Wasser: ";
//char sensor3Name[] = "nix: ";
//char sensor4Name[] = "nix: ";
//ende TEMP
//Durchflusssensor
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;                              
int hallsensor = 19;    //The pin location of the sensor

void rpm ()     //This is the function that the interupt calls
{
 NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal
}
//ende Flow

// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.

// Modified for SPFD5408 Library by Joao Lopes
// Version 0.9.2 - Rotation for Mega and screen initial

// *** SPFD5408 change -- Begin
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
// *** SPFD5408 change -- End

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).

// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0xFFFF
#define BLUE    0xFFE0
#define RED     0x07FF
#define GREEN   0xF81F
#define CYAN    0x07E0
#define MAGENTA 0xF800
#define YELLOW  0x001F
#define WHITE   0x0000

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;

// -- Setup

void setup(void) {
  
  Serial.begin(9600);
  
 
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  
#endif

  tft.reset();
 
  // *** SPFD5408 change -- Begin

// Original code commented

//  uint16_t identifier = tft.readID();
//
//  if(identifier == 0x9325) {
//    Serial.println(F("Found ILI9325 LCD driver"));
//  } else if(identifier == 0x9328) {
//    Serial.println(F("Found ILI9328 LCD driver"));
//  } else if(identifier == 0x7575) {
//    Serial.println(F("Found HX8347G LCD driver"));
//  } else if(identifier == 0x9341) {
//    Serial.println(F("Found ILI9341 LCD driver"));
//  } else if(identifier == 0x8357) {
//    Serial.println(F("Found HX8357D LCD driver"));
//  } else {
//    Serial.print(F("Unknown LCD driver chip: "));
//    Serial.println(identifier, HEX);
//    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
//    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
//    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
//    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
//    Serial.println(F("Also if using the breakout, double-check that all wiring"));
//    Serial.println(F("matches the tutorial."));
//    return;
// }
 
//  tft.begin(identifier);

  // Code changed to works 
  
  tft.begin(0x9341); // SDFP5408

  tft.setRotation(0); // Need for the Mega, please changed for your choice or rotation initial

  // *** SPFD5408 change -- End
//Temp anfang
}
void writeTimeToScratchpad(byte* address)
{
  //reset the bus
  ds.reset();
  //select our sensor
  ds.select(address);
  //CONVERT T function call (44h) which puts the temperature into the scratchpad
  ds.write(0x44,1);
  //sleep a second for the write to take place
  delay(1000);
}

void readTimeFromScratchpad(byte* address, byte* data)
{
  //reset the bus
  ds.reset();
  //select our sensor
  ds.select(address);
  //read the scratchpad (BEh)
  ds.write(0xBE);
  for (byte i=0;i<9;i++){
    data[i] = ds.read();
  }
}
 
float getTemperature(byte* address)
{
  int tr;
  byte data[12];
 
  writeTimeToScratchpad(address);
 
  readTimeFromScratchpad(address,data);
 
  //put in temp all the 8 bits of LSB (least significant byte)
  tr = data[0];
 
  //check for negative temperature
  if (data[1] > 0x80)
  {
    tr = !tr + 1; //two's complement adjustment
    tr = tr * -1; //flip value negative.
  }
 
  //COUNT PER Celsius degree (10h)
  int cpc = data[7];
  //COUNT REMAIN (0Ch)
  int cr = data[6];
 
  //drop bit 0
  tr = tr >> 1;
 
  return tr - (float)0.25 + (cpc - cr)/(float)cpc;

// temp ende
//flow beginn
{
 pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
 Serial.begin(9600); //This is the setup function where the serial port is initialised,
 attachInterrupt(0, rpm, RISING); //and the interrupt is attached
 }
//flow ende
}
void loop(void) {

//Temp beginn
{
  float temp1 = getTemperature(sensor1);
  float temp2 = getTemperature(sensor2);
  //float temp3 = getTemperature(sensor3);
  //float temp4 = getTemperature(sensor4);
 
 
  
  Serial.print(sensor1Name);
  Serial.print(temp1);
  Serial.println(" Celsius");
 
  Serial.print(sensor2Name);
  Serial.print(temp2);
  Serial.println(" Celsius");
 
  //Serial.print(sensor3Name);
  //Serial.print(temp3);
  //Serial.println(" Celsius");
 
  //Serial.print(sensor4Name);
  //Serial.print(temp4);
  //Serial.println(" Celsius");
 
  Serial.println();
  delay(1000);
}
//Temp Ende
//Flow Beginn
NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
 sei();            //Enables interrupts
 delay (1000);      //Wait 1 second
 cli();            //Disable interrupts
 Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
 Serial.print (Calc, DEC); //Prints the number calculated above
 Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
//flow ende

  
  for(uint8_t rotation=2; rotation<3; rotation++) {
    tft.setRotation(rotation);
    testText();
    delay(2000);
  }
}

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(BLACK);
  tft.fillScreen(RED);
  tft.fillScreen(GREEN);
  tft.fillScreen(BLUE);
  tft.fillScreen(BLACK);
  return micros() - start;
}

unsigned long testText() 
{
  tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(3);
  tft.println(sensor1Name); 
  tft.setTextColor(YELLOW); tft.setTextSize(3);
  tft.println();
  tft.setTextColor(RED);    tft.setTextSize(3);
  tft.println(sensor2Name);
  tft.println();
  tft.setTextColor (BLUE);
  tft.println("Wasserfluss");
  tft.setTextColor(GREEN);
  tft.setTextSize(3);
  tft.println(Calc, DEC);
  tft.setTextSize(2);
  tft.println();
  tft.setTextSize(2);
  tft.println();
  return micros() - start;
}

Have you tried making temp1 and temp2 globals?

everytime i try to print the temperature on the LCD i get the mentioned error.

So you posted some code that compiles properly. All we can assume, then, is that you are doing something wrong, like trying to print the value in the variable that is local to loop() in some other function.

how do i make them global?

Move the definitions outside the functions.

i dont know how i can get it out of the actual function. i usually do more copy/paste from existing code.

i actually took 3 programs and merged them into one...

i have trouble understanding why it would print it correct in the serial monitor, but not let me use the same value elsewhere...

just realised i posted the error free code…
here the bad code:

//Temperatursensor
#include <OneWire.h>
#include <DallasTemperature.h>
 
OneWire  ds(17); //pin für ds1820
 
//DeviceAdressen der einzelnen ds1820 Temperatursensoren angeben. (loop anpassen)
DeviceAddress sensor1 = { 0x28, 0x70, 0x42, 0x8, 0x0, 0x0, 0x80, 0x7C };
DeviceAddress sensor2 = { 0x28, 0xFF, 0xC2, 0xA7, 0x74, 0x16, 0x4, 0x90 }; //Knoten
//DeviceAddress sensor3 = { 0x10, 0x11, 0x40, 0xC0, 0x1, 0x8, 0x0, 0x9A };
//DeviceAddress sensor4 = { 0x10, 0x77, 0x38, 0x57, 0x2, 0x8, 0x0, 0x3B };
 
char sensor1Name[] = "CPU: ";
char sensor2Name[] = "Wasser: ";
//char sensor3Name[] = "nix: ";
//char sensor4Name[] = "nix: ";

//ende TEMP
//Durchflusssensor
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;                              
int hallsensor = 19;    //The pin location of the sensor

void rpm ()     //This is the function that the interupt calls
{
 NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal
}
//ende Flow

// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.

// Modified for SPFD5408 Library by Joao Lopes
// Version 0.9.2 - Rotation for Mega and screen initial

// *** SPFD5408 change -- Begin
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
// *** SPFD5408 change -- End

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).

// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0xFFFF
#define BLUE    0xFFE0
#define RED     0x07FF
#define GREEN   0xF81F
#define CYAN    0x07E0
#define MAGENTA 0xF800
#define YELLOW  0x001F
#define WHITE   0x0000

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;

// -- Setup

void setup(void) {
  
  Serial.begin(9600);
  
 
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  
#endif

  tft.reset();
 
  // *** SPFD5408 change -- Begin

// Original code commented

//  uint16_t identifier = tft.readID();
//
//  if(identifier == 0x9325) {
//    Serial.println(F("Found ILI9325 LCD driver"));
//  } else if(identifier == 0x9328) {
//    Serial.println(F("Found ILI9328 LCD driver"));
//  } else if(identifier == 0x7575) {
//    Serial.println(F("Found HX8347G LCD driver"));
//  } else if(identifier == 0x9341) {
//    Serial.println(F("Found ILI9341 LCD driver"));
//  } else if(identifier == 0x8357) {
//    Serial.println(F("Found HX8357D LCD driver"));
//  } else {
//    Serial.print(F("Unknown LCD driver chip: "));
//    Serial.println(identifier, HEX);
//    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
//    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
//    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
//    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
//    Serial.println(F("Also if using the breakout, double-check that all wiring"));
//    Serial.println(F("matches the tutorial."));
//    return;
// }
 
//  tft.begin(identifier);

  // Code changed to works 
  
  tft.begin(0x9341); // SDFP5408

  tft.setRotation(0); // Need for the Mega, please changed for your choice or rotation initial

  // *** SPFD5408 change -- End
//Temp anfang
}
void writeTimeToScratchpad(byte* address)
{
  //reset the bus
  ds.reset();
  //select our sensor
  ds.select(address);
  //CONVERT T function call (44h) which puts the temperature into the scratchpad
  ds.write(0x44,1);
  //sleep a second for the write to take place
  delay(1000);
}

void readTimeFromScratchpad(byte* address, byte* data)
{
  //reset the bus
  ds.reset();
  //select our sensor
  ds.select(address);
  //read the scratchpad (BEh)
  ds.write(0xBE);
  for (byte i=0;i<9;i++){
    data[i] = ds.read();
  }
}
 
float getTemperature(byte* address)
{
  int tr;
  byte data[12];
 
  writeTimeToScratchpad(address);
 
  readTimeFromScratchpad(address,data);
 
  //put in temp all the 8 bits of LSB (least significant byte)
  tr = data[0];
 
  //check for negative temperature
  if (data[1] > 0x80)
  {
    tr = !tr + 1; //two's complement adjustment
    tr = tr * -1; //flip value negative.
  }
 
  //COUNT PER Celsius degree (10h)
  int cpc = data[7];
  //COUNT REMAIN (0Ch)
  int cr = data[6];
 
  //drop bit 0
  tr = tr >> 1;
 
  return tr - (float)0.25 + (cpc - cr)/(float)cpc;

// temp ende
//flow beginn
{
 pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
 Serial.begin(9600); //This is the setup function where the serial port is initialised,
 attachInterrupt(0, rpm, RISING); //and the interrupt is attached
 }
//flow ende
}
void loop(void) {

//Temp beginn
{
  float temp1 = getTemperature(sensor1);
  float temp2 = getTemperature(sensor2);
  //float temp3 = getTemperature(sensor3);
  //float temp4 = getTemperature(sensor4);
 
   
  Serial.print(sensor1Name);
  Serial.print(temp1);
  Serial.println(" Celsius");
 
  Serial.print(sensor2Name);
  Serial.print(temp2);
  Serial.println(" Celsius");
 
  //Serial.print(sensor3Name);
  //Serial.print(temp3);
  //Serial.println(" Celsius");
 
  //Serial.print(sensor4Name);
  //Serial.print(temp4);
  //Serial.println(" Celsius");
 
  Serial.println();
  delay(1000);
}
//Temp Ende
//Flow Beginn
NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
 sei();            //Enables interrupts
 delay (1000);      //Wait 1 second
 cli();            //Disable interrupts
 Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
 Serial.print (Calc, DEC); //Prints the number calculated above
 Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
//flow ende

  
  for(uint8_t rotation=2; rotation<3; rotation++) {
    tft.setRotation(rotation);
    testText();
    delay(2000);
  }
}

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(BLACK);
  tft.fillScreen(RED);
  tft.fillScreen(GREEN);
  tft.fillScreen(BLUE);
  tft.fillScreen(BLACK);
  return micros() - start;
}

unsigned long testText() 
{
  tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(3);
  tft.println(sensor1Name); 
  tft.setTextColor(YELLOW); tft.setTextSize(3);
  tft.println(temp1);
  tft.setTextColor(RED);    tft.setTextSize(3);
  tft.println(sensor2Name);
  tft.println(temp2);
  tft.setTextColor (BLUE);
  tft.println("Wasserfluss");
  tft.setTextColor(GREEN);
  tft.setTextSize(3);
  tft.println(Calc, DEC);
  tft.setTextSize(2);
  tft.println();
  tft.setTextSize(2);
  tft.println();
  return micros() - start;
}

SGC2504: i dont know how i can get it out of the actual function.

OneWire  ds(17); //pin für ds1820

"ds" is defined outside the functions and has global scope.

i have trouble understanding why it would print it correct in the serial monitor, but not let me use the same value elsewhere...

Because the scope is incorrect.

At the top of this Forum is a list of topics by Nick Gammon that contains a number of questions that newcomer’s often ask. Under the topic C++ Programming in that post is a discussion about Scope. Read that and then come back here with your remaining questions.

got it solved with a “workaround”
Thanks for your Help!

//Temperatursensor
#include <OneWire.h>
#include <DallasTemperature.h>
 
OneWire  ds(17); //pin für ds1820

int Temp1;
int Temp2;

//DeviceAdressen der einzelnen ds1820 Temperatursensoren angeben. (loop anpassen)
DeviceAddress sensor1 = { 0x28, 0x70, 0x42, 0x8, 0x0, 0x0, 0x80, 0x7C };
DeviceAddress sensor2 = { 0x28, 0xFF, 0xC2, 0xA7, 0x74, 0x16, 0x4, 0x90 }; //Knoten
//DeviceAddress sensor3 = { 0x10, 0x11, 0x40, 0xC0, 0x1, 0x8, 0x0, 0x9A };
//DeviceAddress sensor4 = { 0x10, 0x77, 0x38, 0x57, 0x2, 0x8, 0x0, 0x3B };

char sensor1Name[] = "CPU: ";
char sensor2Name[] = "Wasser: ";
//char sensor3Name[] = "nix: ";
//char sensor4Name[] = "nix: ";

//ende TEMP
//Durchflusssensor
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;                              
int hallsensor = 19;    //The pin location of the sensor

void rpm ()     //This is the function that the interupt calls
{
 NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal
}
//ende Flow

// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.

// Modified for SPFD5408 Library by Joao Lopes
// Version 0.9.2 - Rotation for Mega and screen initial

// *** SPFD5408 change -- Begin
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
// *** SPFD5408 change -- End

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).

// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0xFFFF
#define BLUE    0xFFE0
#define RED     0x07FF
#define GREEN   0xF81F
#define CYAN    0x07E0
#define MAGENTA 0xF800
#define YELLOW  0x001F
#define WHITE   0x0000

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;

// -- Setup

void setup(void) {
  
  Serial.begin(9600);
  
 
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  
#endif

  tft.reset();
 
  // *** SPFD5408 change -- Begin

// Original code commented

//  uint16_t identifier = tft.readID();
//
//  if(identifier == 0x9325) {
//    Serial.println(F("Found ILI9325 LCD driver"));
//  } else if(identifier == 0x9328) {
//    Serial.println(F("Found ILI9328 LCD driver"));
//  } else if(identifier == 0x7575) {
//    Serial.println(F("Found HX8347G LCD driver"));
//  } else if(identifier == 0x9341) {
//    Serial.println(F("Found ILI9341 LCD driver"));
//  } else if(identifier == 0x8357) {
//    Serial.println(F("Found HX8357D LCD driver"));
//  } else {
//    Serial.print(F("Unknown LCD driver chip: "));
//    Serial.println(identifier, HEX);
//    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
//    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
//    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
//    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
//    Serial.println(F("Also if using the breakout, double-check that all wiring"));
//    Serial.println(F("matches the tutorial."));
//    return;
// }
 
//  tft.begin(identifier);

  // Code changed to works 
  
  tft.begin(0x9341); // SDFP5408

  tft.setRotation(0); // Need for the Mega, please changed for your choice or rotation initial

  // *** SPFD5408 change -- End
//Temp anfang
}
void writeTimeToScratchpad(byte* address)
{
  //reset the bus
  ds.reset();
  //select our sensor
  ds.select(address);
  //CONVERT T function call (44h) which puts the temperature into the scratchpad
  ds.write(0x44,1);
  //sleep a second for the write to take place
  delay(1000);
}

void readTimeFromScratchpad(byte* address, byte* data)
{
  //reset the bus
  ds.reset();
  //select our sensor
  ds.select(address);
  //read the scratchpad (BEh)
  ds.write(0xBE);
  for (byte i=0;i<9;i++){
    data[i] = ds.read();
  }
}
 
float getTemperature(byte* address)
{
  int tr;
  byte data[12];
 
  writeTimeToScratchpad(address);
 
  readTimeFromScratchpad(address,data);
 
  //put in temp all the 8 bits of LSB (least significant byte)
  tr = data[0];
 
  //check for negative temperature
  if (data[1] > 0x80)
  {
    tr = !tr + 1; //two's complement adjustment
    tr = tr * -1; //flip value negative.
  }
 
  //COUNT PER Celsius degree (10h)
  int cpc = data[7];
  //COUNT REMAIN (0Ch)
  int cr = data[6];
 
  //drop bit 0
  tr = tr >> 1;
 
  return tr - (float)0.25 + (cpc - cr)/(float)cpc;


// temp ende
//flow beginn
{
 pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
 Serial.begin(9600); //This is the setup function where the serial port is initialised,
 attachInterrupt(0, rpm, RISING); //and the interrupt is attached
 }
//flow ende
}
void loop(void) {

//Temp beginn
{
  float temp1 = getTemperature(sensor1);
  float temp2 = getTemperature(sensor2);
  //float temp3 = getTemperature(sensor3);
  //float temp4 = getTemperature(sensor4);
  
Temp1 = temp1;
Temp2 = temp2;   
  Serial.print(sensor1Name);
  Serial.print(temp1);
  Serial.println(" Celsius");
 
  Serial.print(sensor2Name);
  Serial.print(temp2);
  Serial.println(" Celsius");
 
  //Serial.print(sensor3Name);
  //Serial.print(temp3);
  //Serial.println(" Celsius");
 
  //Serial.print(sensor4Name);
  //Serial.print(temp4);
  //Serial.println(" Celsius");
 
  Serial.println();
  delay(1000);
}
//Temp Ende
//Flow Beginn
NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
 sei();            //Enables interrupts
 delay (1000);      //Wait 1 second
 cli();            //Disable interrupts
 Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
 Serial.print (Calc, DEC); //Prints the number calculated above
 Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
//flow ende

  
  for(uint8_t rotation=3; rotation<4; rotation++) {
    tft.setRotation(rotation);
    testText();
    delay(2000);
  }
}

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(BLACK);
  tft.fillScreen(RED);
  tft.fillScreen(GREEN);
  tft.fillScreen(BLUE);
  tft.fillScreen(BLACK);
  return micros() - start;
}

unsigned long testText() 
{
  tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(3);
  tft.println(sensor1Name); 
  tft.setTextColor(YELLOW); tft.setTextSize(3);
  tft.println(Temp1);
  tft.setTextColor(RED);    tft.setTextSize(3);
  tft.println(sensor2Name);
  tft.println(Temp2);
  tft.setTextColor (BLUE);
  tft.println("Wasserfluss");
  tft.setTextColor(GREEN);
  tft.setTextSize(3);
  tft.println(Calc, DEC);
  tft.setTextSize(2);
  tft.println();
  tft.setTextSize(2);
  tft.println();
  return micros() - start;
}

Except that in your original, "temp1" and "temp2" were "float"s, not "int"s.

Much simpler "workaround"

float temp1;
float temp2;

void loop(void) {

//Temp beginn
{
  temp1 = getTemperature(sensor1);
  temp2 = getTemperature(sensor2);
....
....
}
unsigned long testText()
{
  tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(3);
  tft.println(sensor1Name);
  tft.setTextColor(YELLOW); tft.setTextSize(3);
  tft.println(temp1);
  tft.setTextColor(RED);    tft.setTextSize(3);
  tft.println(sensor2Name);
  tft.println(temp2);
  tft.setTextColor (BLUE);
  tft.println("Wasserfluss");
  tft.setTextColor(GREEN);
  tft.setTextSize(3);
  tft.println(Calc, DEC);
  tft.setTextSize(2);
  tft.println();
  tft.setTextSize(2);
  tft.println();
  return micros() - start;
}