Frage | 2.2 TFT | Ausgabe wenn Wert sich ändert |

Hallo zusammen,

ich sitze nun schon lange an meinen Problem. Ich möchte eine Ausgabe einer Temperatur auf einem 2,2TFT nur dann erfolgen lassen, wenn sich die Temperatur ändert.

Mein Problem ist das ich es nicht hinbekomme ein Abfrage/Prüfung dafür zu schreiben. Nehme ich mir eine Hilfsvariable so initialisiert er sie jedes mal neu.....dies tut er auch mit der globalen Variable.

Ich dachte die void loop() wird als einzige mehr als einmal ausgeführt ?!

void loop(void) {
  
  float T0=22;                                                                   // Nenntemperatur des NTC-Widerstands in °C
  float R0=1450 ;                                                                 // Nennwiderstand des NTC-Sensors in Ohm
  float T1=80;                                                                   // erhöhte Temperatur des NTC-Widerstands in °C
  float R1=206;                                                                  // Widerstand des NTC-Sensors bei erhöhter Temperatur in Ohm
  float Vorwiderstand = 220;                                                    // Vorwiderstand in Ohm  
  int analogPinA2 = A2;
  int aValue=analogRead(A2);  
  long temp = temperature_NTC(T0, R0, T1, R1, Vorwiderstand, aValue/MAXANALOGREAD);
    
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9340_WHITE);  tft.setTextSize(3);
  tft.println("Oeltemperatur:");
  tft.setTextSize(1);
  tft.println();
  tft.setTextColor(ILI9340_WHITE);
  tft.setCursor(0, 30);
  tft.setTextSize(5);
  
  
  if(temp != tempAlt){
  tft.fillRect(0,30,60,40,0x0000);
  tft.print(temp);
  long tempAlt = temp;
  delay(500);
  }

die Variable tempAlt befindet sich jetzt bewusst nicht in dem Codestück.

Vielleicht versteht mich ja jemand und kann mir helfen !!

Danke !!

lg

y4y0

Weil es falsch ist. Deklariere sie in der loop als static oder normal als GLOBAL