add an circle who change color in temperature3 way possible for differente temperature if the temperature :
//Libraries
#include "TFT_eSPI.h" //TFT LCD library
#include "DHT.h" // DHT library

//Definitions
#define DHTPIN 0 //Define signal pin of DHT sensor
// #define DHTPIN PIN_WIRE_SCL //Use I2C port as Digital Port */
#define DHTTYPE DHT11 //Define DHT sensor type

//Initializations
DHT dht(DHTPIN, DHTTYPE); //Initializing DHT sensor
TFT_eSPI tft; //Initializing TFT LCD
TFT_eSprite spr = TFT_eSprite(&tft); //Initializing buffer

//Soil Moisture Sensor definitions
int sensorPin = A1; //Define variable to store soil moisture sensor pin
int sensorValue = 0; //Define variable to store soil moisture sensor value

void setup() {
Serial.begin(9600); //Start serial communication

pinMode(WIO_LIGHT, INPUT); //Set light sensor pin as INPUT
pinMode(WIO_BUZZER, OUTPUT); //Set buzzer pin as OUTPUT

dht.begin(); //Start DHT sensor
tft.begin(); //Start TFT LCD
tft.setRotation(3); //Set TFT LCD rotation
spr.createSprite(TFT_HEIGHT,TFT_WIDTH); //Create buffer
}

void loop() {
int t = dht.readTemperature(); //Assign variable to store temperature
int h = dht.readHumidity(); //Assign variable to store humidity
int light = analogRead(WIO_LIGHT); //Assign variable to store light sensor values

//titre
spr.fillSprite(TFT_WHITE);
spr.fillRect(0,0,320,50,TFT_BLUE);
spr.setTextColor(TFT_WHITE);
spr.setTextSize(3);
spr.drawString("biotechnica",50,15);

/*lignes
spr.drawFastVLine(160,50,190,TFT_BLUE);
spr.drawFastHLine(0,140,320,TFT_BLUE);
*/
// temperature
spr.setTextColor(TFT_BLACK);

//thermometre

/**/ if(dht.readTemperature() < 15){
spr.fillRect(14,160,4,65,TFT_BLUE);
}
else if (dht.readTemperature() > 15 && dht.readTemperature()<18){
spr.fillRect(14,130,4,95,TFT_BLUE);
}
else if (dht.readTemperature() > 18 && dht.readTemperature()<21){
spr.fillRect(14,100,4,125,TFT_RED);
}
else if (dht.readTemperature() > 21 && dht.readTemperature()<24){
spr.fillRect(14,70,4,155,TFT_RED);
}
else if (dht.readTemperature() > 24){
spr.fillRect(14,40,4,185,TFT_RED);
analogWrite(WIO_BUZZER, 10); //beep the buzzer
delay(100);
analogWrite(WIO_BUZZER, 0); //Silence the buzzer
delay(100);
}

spr.fillCircle(16,220,6,TFT_RED);

spr.setTextSize(2);

spr.setTextSize(2);
spr.drawNumber(t,30,210); //Display temperature values
spr.drawString("C",55,210);

/humiditee
spr.setTextSize(2);
spr.drawString("Humidity",35,40);
spr.setTextSize(3);
spr.drawNumber(h,45,190); //Display humidity values
spr.drawString("%RH",70,190);/

//soil moisture
sensorValue = analogRead(sensorPin); //Store sensor values
sensorValue = map(sensorValue,1023,400,0,100); //Map sensor values
spr.setTextSize(2);
spr.drawString("Soil Moisture",162,65);
spr.setTextSize(3);
spr.drawNumber(sensorValue,200,95); //Display sensor values as percentage
spr.drawString("%",260,95);

//Setting light
spr.setTextSize(2);
spr.drawString("Light",200,160);
spr.setTextSize(3);
light = map(light,0,1023,0,100); //Map sensor values
spr.drawNumber(light,205,190); //Display sensor values as percentage
spr.drawString("%",245,190);

//Condition for low soil moisture
if(sensorValue < 10){
spr.fillSprite(TFT_RED);
spr.drawString("Time to water!",35,100);
analogWrite(WIO_BUZZER, 150); //beep the buzzer
delay(1000);
analogWrite(WIO_BUZZER, 0); //Silence the buzzer
delay(1000);
}

spr.pushSprite(0,0); //Push to LCD
delay(50);

}



To implement a feature where a circle changes color based on different temperature ranges on your TFT display, you can simplify and optimize your current setup. This involves creating a function to update the circle color based on the temperature. Here’s how you can modify your code to include a color-changing circle based on temperature:

Optimize Temperature Reading: Instead of reading the temperature multiple times within the loop, read it once and store it in a variable.
Create a Function for Color Determination: This makes your code cleaner and easier to maintain.
Update Circle Color Based on Temperature: Use the function to determine the color and then update the circle.
Here's the revised part of your code incorporating these changes:

Step 1: Read Temperature Once
Instead of calling dht.readTemperature() multiple times, read it once at the beginning of the loop and use the value throughout:


void loop() {
  float temperature = dht.readTemperature(); // Only read once and reuse this value
  int h = dht.readHumidity();
  int light = analogRead(WIO_LIGHT);
Step 2: Define a Function to Get Color Based on Temperature
Add this function before the setup() function:


uint32_t getColorForTemperature(float temp) {
  if (temp < 15) {
    return TFT_BLUE;
  } else if (temp < 18) {
    return TFT_BLUE;
  } else if (temp < 21) {
    return TFT_RED;
  } else if (temp < 24) {
    return TFT_RED;
  } else {
    return TFT_RED; // Consider adding a different color for clarity if needed
  }
}
Step 3: Update the Circle Based on Temperature
Modify the temperature display section in your loop() function:


  // Update circle color based on temperature
  uint32_t color = getColorForTemperature(temperature);
  spr.fillCircle(16, 220, 6, color); // Draw circle with dynamic color

  // Display temperature
  spr.setTextSize(2);
  spr.drawNumber((int)temperature, 30, 210); // Display temperature value as integer
  spr.drawString("C", 55, 210);

  // Additional code for thermometer visual (optional)
  // Update the thermometer visual if necessary, similar to the above logic
This setup ensures that your code efficiently updates the circle color based on the temperature range, and it only reads the temperature from the sensor once per loop iteration, reducing redundancy and potential sensor reading errors.

Make sure the rest of your loop() function accommodates these changes and that the circle's color change is visually clear on your display. Adjust the colors as needed to make sure they are distinct and meaningful based on your application's requirements.