TFT 2.4 SPI + TFT_eSPI touch doesn't work

Hardware :

  • ESP32 Wroom Dev kit
  • TFT 2.4 touch screen SPI
  • BME280

Libraries:

  • TFT_eSPI

i made a sketch where i want to display hour on a first screen and bme280 sensors on a second screen.
What i want to do is to switch between the 2 display using touch function. A simple touch on screen and it toggles.
But it doesn't work at all.

Here code in loop

void loop()
{
  if (chEcran == false)
  {
    pressed = tft.getTouch(&a, &b);
    if (pressed)
    {
      affichage = !affichage;
      chEcran = !chEcran;
    }
    if (affichage == false)
    {
      dessin_horloge();
      affichage = !affichage;
    }
    horloge();
  }
  else
  {
    pressed = tft.getTouch(&a, &b);
    if (pressed)
    {
      affichage = !affichage;
      chEcran = !chEcran;
    }
    if (affichage == false)
    {
      affichage_bme280();
      affichage = !affichage;
    }
    bme280();
  }
server.handleClient();
}

I'm sure touch works because i can calibrate my screen and it displays first screen.

Please post your code.

Grrr.

All the code

#include <Arduino.h>
#include <WiFi.h>
#include <WebServer.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <TFT_eSPI.h>
#include <SPI.h>
#include <time.h>

//fonctions
static uint8_t conv2d(const char *p);
void handle_OnConnect();
void handle_NotFound();
String SendHTML(float temperature, float humidity, float pressure, float altitude, float altIGN, float pnmm);
void horloge();
void dessin_horloge();
void bme280();
void affichage_bme280();

const char *ssid = "ssid";
const char *mdp = "password";

#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
float temperature, humidity, pressure, altitude, altIGN = 481.38, pnmm, alpha, rosee;
int x = 180, y = 0, offst = 30;

WebServer server(80);

TFT_eSPI tft = TFT_eSPI();
#define TFT_GREY 0x3186 // New colour
#define TFT_TOMATE 0xD942
#define TFT_JADE 0x8752
#define TFT_ANIS 0x9F4A
#define TFT_AZUR 0x769E
#define TFT_GRIS 0xCE79
#define TFT_GREGE 0xBD73
#define TFT_CELADON 0x8532
#define TFT_NOISETTE 0x92A5
#define TFT_MENTHE 0x57D1
#define TFT_SAUGE 0x6CEE
#define VERT_PRINTEMPS 0x07EF
#define CHARTREUSE 0xC7A6
#define font 1

//horloge
float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0; // Saved H, M, S x & y multipliers
float sdeg = 0, mdeg = 0, hdeg = 0;
uint16_t osx = 120, osy = 120, omx = 120, omy = 120, ohx = 120, ohy = 120; // Saved H, M, S x & y coords
uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0;
uint32_t targetTime = 0; // for next 1 second timeout

static uint8_t conv2d(const char *p);                                                // Forward declaration needed for IDE 1.6.x
uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6); // Get H, M, S from compile time

bool initial = 1;

//TOUCH
uint16_t a = 0, b = 0; // To store the touch coordinates
boolean chEcran = false, affichage = false;

//date et heure
time_t heure;
const int decalage = 0; // la valeur dépend du fuseau horaire.
const int daylight = 2; // décalage de l'heure d'été

void setup()
{
  Serial.begin(115200);
  delay(100);

  tft.init();
  tft.fillScreen(TFT_BLACK);
  tft.setRotation(3);
  tft.setTextColor(TFT_ORANGE, TFT_GREY);
  tft.setTextSize(2);
  tft.setCursor(0, 30);
  tft.println("TEST ECRAN");
  // Use this calibration code in setup():
  uint16_t calData[5] = {484, 3356, 347, 3371, 3};
  tft.setTouch(calData);

  if (bme.begin(0x76))
  {
    Serial.println(F("Capteur BME280 trouvé"));
    tft.println(F("Capteur BME 280 trouv\x82"));
  }
  else
  {
    Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
    tft.println(F("Pas de capteur trouv\x82"));
    while (1)
      delay(10);
  }

  Serial.println("Connecting to ");
  Serial.println(ssid);
  tft.println((String) "Se connecte \x85" + ssid);

  //connect to your local wi-fi network
  WiFi.begin(ssid, mdp);
  //check wi-fi is connected to wi-fi network
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(1000);
    Serial.print(".");
    tft.print(".");
  }
  Serial.println("");
  tft.println("");
  Serial.println("WiFi connected..!");
  tft.println("WiFi connect\x82...");
  Serial.print("Got IP: ");
  tft.print("IP = ");
  Serial.println(WiFi.localIP());
  tft.println(WiFi.localIP());

  server.on("/", handle_OnConnect);
  server.onNotFound(handle_NotFound);

  server.begin();
  Serial.println("HTTP server started");
  tft.println("HTTP server d\x82marr\x82");

  //********************************
  configTime(decalage * 3600, daylight * 3600, "fr.pool.ntp.org"); //serveurs canadiens ca.pool.ntp.org
  // en Europe, europe.pool.ntp.org ou fr.pool.ntp.org

  Serial.println("Attente date et heure");
  tft.println("Attente date et heure");
  while (time(nullptr) <= 100000)
  {
    Serial.print(".");
    tft.print(".");
    delay(1000);
  }
}

void loop()
{
  if (chEcran == false)
  {
    boolean pressed = tft.getTouch(&a, &b);
    //Serial.println((String)"Ligne 138. a = " + a + " b = " + b);
    if (pressed)
    {
      affichage = !affichage;
      chEcran = !chEcran;
    }
    if (affichage == false)
    {
      dessin_horloge();
      affichage = !affichage;
    }
    horloge();
  }
  else
  {
    boolean pressed = tft.getTouch(&a, &b);
    if (pressed)
    {
      affichage = !affichage;
      chEcran = !chEcran;
    }
    if (affichage == false)
    {
      affichage_bme280();
      affichage = !affichage;
    }
    bme280();
  }
server.handleClient();
}

//FONCTIONS
static uint8_t conv2d(const char *p)
{
  uint8_t v = 0;
  if ('0' <= *p && *p <= '9')
    v = *p - '0';
  return 10 * v + *++p - '0';
}

void bme280()
{
  tft.setTextColor(VERT_PRINTEMPS, TFT_GREY);
  tft.setCursor(x, y, font);
  tft.print(temperature);
  tft.print(" C");
  y = offst;
  tft.setCursor(x, y, font);
  tft.print(humidity);
  tft.print(" %");
  y += offst;
  tft.setCursor(x, y, font);
  tft.print(pressure);
  tft.print(" hpa");
  y += offst;
  tft.setCursor(x, y, font);
  //calcul du point de rosée  (formule de Heinrich Gustav Magnus-Tetens)
  alpha = log(humidity / 100.0F) + (17.27 * temperature) / (237.3 + temperature);
  rosee = (237.3 * alpha) / (17.27 - alpha);
  tft.print(rosee);
  tft.print(" C");
  y += offst;
  tft.setCursor(x, y);
  tft.print(altIGN);
  tft.print(" m");
  y += offst;
  tft.setCursor(x, y);
  tft.print(pnmm);
  tft.print(" hpa");
  y = 0;
}
void affichage_bme280()
{
  tft.fillScreen(TFT_GREY);
  tft.setTextColor(TFT_AZUR, TFT_GREY); // Adding a background colour erases previous text automatically
  tft.setCursor(0, 0, font);
  tft.print("Temp\x82rature : ");
  tft.setCursor(0, 30, font);
  tft.print("Humidit\x82 : ");
  tft.setCursor(0, 60, font);
  tft.print("Pression : ");
  tft.setCursor(0, 90, font);
  tft.print("Point de ros\x82\x65 : ");
  tft.setCursor(0, 120);
  tft.print("Alt. corrig\x82\x65 :");
  tft.setCursor(0, 150);
  tft.print("Pression NMM :");

  tft.drawLine(0, 180, 320, 180, TFT_TOMATE);
  tft.setCursor(40, 192);
  tft.setTextColor(TFT_SAUGE, TFT_GREY);
  tft.setTextFont(2);
  tft.print("ESP32-Wroom Upesy");
}
void dessin_horloge()
{
  //Dessine l'horloge
  //tft.setRotation(0);

  //tft.fillScreen(TFT_BLACK);
  //tft.fillScreen(TFT_RED);
  //tft.fillScreen(TFT_GREEN);
  //tft.fillScreen(TFT_BLUE);
  //tft.fillScreen(TFT_BLACK);
  tft.fillScreen(TFT_GREY);

  tft.setTextColor(TFT_WHITE, TFT_GREY); // Adding a background colour erases previous text automatically

  // Draw clock face
  tft.fillCircle(120, 120, 118, TFT_GREEN);
  tft.fillCircle(120, 120, 110, TFT_BLACK);

  // Draw 12 lines
  for (int i = 0; i < 360; i += 30)
  {
    sx = cos((i - 90) * 0.0174532925);
    sy = sin((i - 90) * 0.0174532925);
    x0 = sx * 114 + 120;
    yy0 = sy * 114 + 120;
    x1 = sx * 100 + 120;
    yy1 = sy * 100 + 120;

    tft.drawLine(x0, yy0, x1, yy1, TFT_GREEN);
  }

  // Draw 60 dots
  for (int i = 0; i < 360; i += 6)
  {
    sx = cos((i - 90) * 0.0174532925);
    sy = sin((i - 90) * 0.0174532925);
    x0 = sx * 102 + 120;
    yy0 = sy * 102 + 120;
    // Draw minute markers
    tft.drawPixel(x0, yy0, TFT_WHITE);

    // Draw main quadrant dots
    if (i == 0 || i == 180)
      tft.fillCircle(x0, yy0, 2, TFT_WHITE);
    if (i == 90 || i == 270)
      tft.fillCircle(x0, yy0, 2, TFT_WHITE);
  }

  tft.fillCircle(120, 121, 3, TFT_WHITE);

  // Draw text at position 120,260 using fonts 4
  // Only font numbers 2,4,6,7 are valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : . - a p m
  // Font 7 is a 7 segment font and only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : .
  //tft.drawCentreString("Time flies", 120, 260, 4);

  targetTime = millis() + 1000;
}
void horloge()
{
  if (targetTime < millis())
  {
    targetTime += 1000;
    time(&heure);
    struct tm *timeinfo;
    timeinfo = localtime(&heure);
    //ss++; // Advance second
    ss = timeinfo->tm_sec;
    mm = timeinfo->tm_min;
    hh = timeinfo->tm_hour;
    /*
  if (ss == 60)
  {
    ss = 0;
    mm++; // Advance minute
    if (mm > 59)
    {
      mm = 0;
      hh++; // Advance hour
      if (hh > 23)
      {
        hh = 0;
      }
    }
  }
  */

    // Pre-compute hand degrees, x & y coords for a fast screen update
    sdeg = ss * 6;                     // 0-59 -> 0-354
    mdeg = mm * 6 + sdeg * 0.01666667; // 0-59 -> 0-360 - includes seconds
    hdeg = hh * 30 + mdeg * 0.0833333; // 0-11 -> 0-360 - includes minutes and seconds
    hx = cos((hdeg - 90) * 0.0174532925);
    hy = sin((hdeg - 90) * 0.0174532925);
    mx = cos((mdeg - 90) * 0.0174532925);
    my = sin((mdeg - 90) * 0.0174532925);
    sx = cos((sdeg - 90) * 0.0174532925);
    sy = sin((sdeg - 90) * 0.0174532925);

    if (ss == 0 || initial)
    {
      initial = 0;
      // Erase hour and minute hand positions every minute
      tft.drawLine(ohx, ohy, 120, 121, TFT_BLACK);
      ohx = hx * 62 + 121;
      ohy = hy * 62 + 121;
      tft.drawLine(omx, omy, 120, 121, TFT_BLACK);
      omx = mx * 84 + 120;
      omy = my * 84 + 121;
    }

    // Redraw new hand positions, hour and minute hands not erased here to avoid flicker
    tft.drawLine(osx, osy, 120, 121, TFT_BLACK);
    osx = sx * 90 + 121;
    osy = sy * 90 + 121;
    tft.drawLine(osx, osy, 120, 121, TFT_RED);
    tft.drawLine(ohx, ohy, 120, 121, TFT_WHITE);
    tft.drawLine(omx, omy, 120, 121, TFT_WHITE);
    tft.drawLine(osx, osy, 120, 121, TFT_RED);

    tft.fillCircle(120, 121, 3, TFT_RED);
  }
}

void handle_OnConnect()
{
  temperature = bme.readTemperature();
  humidity = bme.readHumidity();
  pressure = bme.readPressure() / 100.0F;
  altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  pnmm = pressure * exp(9.80665 / (287.05 * (temperature + 273.15 + 0.12 * humidity + 0.0065 * altIGN / 2)) * altIGN);
  server.send(200, "text/html", SendHTML(temperature, humidity, pressure, altitude, altIGN, pnmm));
}

void handle_NotFound()
{
  server.send(404, "text/plain", "Not found");
}

String SendHTML(float temperature, float humidity, float pressure, float altitude, float altIGN, float pnmm)
{
  String ptr = "<!DOCTYPE html>";
  ptr += "<html>";
  ptr += "<head>";
  ptr += "<title>ESP32-V4 Station M&eacute;t&eacute;o</title>";
  ptr += "<meta name='viewport' content='width=device-width, initial-scale=1.0'>";
  ptr += "<link href='https://fonts.googleapis.com/css?family=Open+Sans:300,400,600' rel='stylesheet'>";
  ptr += "<style>";
  ptr += "html { font-family: 'Open Sans', sans-serif; display: block; margin: 0px auto; text-align: center;color: #444444;}";
  ptr += "body{margin: 0px;} ";
  ptr += "h1 {margin: 50px auto 30px;color: #FFFFF0} ";
  ptr += ".side-by-side{display: table-cell;vertical-align: middle;position: relative;color: #A9EAFE}";
  ptr += ".text{font-weight: 600;font-size: 19px;width: 200px;}";
  ptr += ".reading{font-weight: 300;font-size: 25px;padding-right: 25px;}";
  ptr += ".temperature .reading{color: #F29C1F;}";
  ptr += ".humidity .reading{color: #3B97D3;}";
  ptr += ".pressure .reading{color: #26B99A;}";
  ptr += ".altitude .reading{color: #955BA5;}";
  ptr += ".altIGN .reading{color: #955BA5;}";
  ptr += ".pnmm .reading{color: #26B99A;}";
  ptr += ".superscript{padding-left: 10px;font-size: 25px;font-weight: 300;}";
  ptr += ".data{padding: 10px;}";
  ptr += ".container{display: table;margin: 0 auto;}";
  ptr += ".icon{width:65px}";
  ptr += "</style>";
  ptr += "<script>\n";
  ptr += "setInterval(loadDoc,5000);\n";
  ptr += "function loadDoc() {\n";
  ptr += "var xhttp = new XMLHttpRequest();\n";
  ptr += "xhttp.onreadystatechange = function() {\n";
  ptr += "if (this.readyState == 4 && this.status == 200) {\n";
  ptr += "document.body.innerHTML =this.responseText}\n";
  ptr += "};\n";
  ptr += "xhttp.open(\"GET\", \"/\", true);\n";
  ptr += "xhttp.send();\n";
  ptr += "}\n";
  ptr += "</script>\n";
  ptr += "</head>";
  ptr += "<body style=\"background-color:#1b1b1b;\">";
  ptr += "<h1>ESP32 Station M&eacute;t&eacute;o</h1>";
  ptr += "<div class='container'>";
  ptr += "<div class='data temperature'>";
  ptr += "<div class='side-by-side icon'>";
  ptr += "<svg enable-background='new 0 0 19.438 54.003'height=54.003px id=Layer_1 version=1.1 viewBox='0 0 19.438 54.003'width=19.438px x=0px xml:space=preserve xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink y=0px><g><path d='M11.976,8.82v-2h4.084V6.063C16.06,2.715,13.345,0,9.996,0H9.313C5.965,0,3.252,2.715,3.252,6.063v30.982";
  ptr += "C1.261,38.825,0,41.403,0,44.286c0,5.367,4.351,9.718,9.719,9.718c5.368,0,9.719-4.351,9.719-9.718";
  ptr += "c0-2.943-1.312-5.574-3.378-7.355V18.436h-3.914v-2h3.914v-2.808h-4.084v-2h4.084V8.82H11.976z M15.302,44.833";
  ptr += "c0,3.083-2.5,5.583-5.583,5.583s-5.583-2.5-5.583-5.583c0-2.279,1.368-4.236,3.326-5.104V24.257C7.462,23.01,8.472,22,9.719,22";
  ptr += "s2.257,1.01,2.257,2.257V39.73C13.934,40.597,15.302,42.554,15.302,44.833z'fill=#F29C21 /></g></svg>";
  ptr += "</div>";
  ptr += "<div class='side-by-side text'>Temp&eacute;rature</div>";
  ptr += "<div class='side-by-side reading'>";
  ptr += temperature;
  ptr += "<span class='superscript'>&deg;C</span></div>";
  ptr += "</div>";
  ptr += "<div class='data humidity'>";
  ptr += "<div class='side-by-side icon'>";
  ptr += "<svg enable-background='new 0 0 29.235 40.64'height=40.64px id=Layer_1 version=1.1 viewBox='0 0 29.235 40.64'width=29.235px x=0px xml:space=preserve xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink y=0px><path d='M14.618,0C14.618,0,0,17.95,0,26.022C0,34.096,6.544,40.64,14.618,40.64s14.617-6.544,14.617-14.617";
  ptr += "C29.235,17.95,14.618,0,14.618,0z M13.667,37.135c-5.604,0-10.162-4.56-10.162-10.162c0-0.787,0.638-1.426,1.426-1.426";
  ptr += "c0.787,0,1.425,0.639,1.425,1.426c0,4.031,3.28,7.312,7.311,7.312c0.787,0,1.425,0.638,1.425,1.425";
  ptr += "C15.093,36.497,14.455,37.135,13.667,37.135z'fill=#3C97D3 /></svg>";
  ptr += "</div>";
  ptr += "<div class='side-by-side text'>Humidit&eacute;</div>";
  ptr += "<div class='side-by-side reading'>";
  ptr += humidity;
  ptr += "<span class='superscript'>%</span></div>";
  ptr += "</div>";
  ptr += "<div class='data pressure'>";
  ptr += "<div class='side-by-side icon'>";
  ptr += "<svg enable-background='new 0 0 40.542 40.541'height=40.541px id=Layer_1 version=1.1 viewBox='0 0 40.542 40.541'width=40.542px x=0px xml:space=preserve xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink y=0px><g><path d='M34.313,20.271c0-0.552,0.447-1,1-1h5.178c-0.236-4.841-2.163-9.228-5.214-12.593l-3.425,3.424";
  ptr += "c-0.195,0.195-0.451,0.293-0.707,0.293s-0.512-0.098-0.707-0.293c-0.391-0.391-0.391-1.023,0-1.414l3.425-3.424";
  ptr += "c-3.375-3.059-7.776-4.987-12.634-5.215c0.015,0.067,0.041,0.13,0.041,0.202v4.687c0,0.552-0.447,1-1,1s-1-0.448-1-1V0.25";
  ptr += "c0-0.071,0.026-0.134,0.041-0.202C14.39,0.279,9.936,2.256,6.544,5.385l3.576,3.577c0.391,0.391,0.391,1.024,0,1.414";
  ptr += "c-0.195,0.195-0.451,0.293-0.707,0.293s-0.512-0.098-0.707-0.293L5.142,6.812c-2.98,3.348-4.858,7.682-5.092,12.459h4.804";
  ptr += "c0.552,0,1,0.448,1,1s-0.448,1-1,1H0.05c0.525,10.728,9.362,19.271,20.22,19.271c10.857,0,19.696-8.543,20.22-19.271h-5.178";
  ptr += "C34.76,21.271,34.313,20.823,34.313,20.271z M23.084,22.037c-0.559,1.561-2.274,2.372-3.833,1.814";
  ptr += "c-1.561-0.557-2.373-2.272-1.815-3.833c0.372-1.041,1.263-1.737,2.277-1.928L25.2,7.202L22.497,19.05";
  ptr += "C23.196,19.843,23.464,20.973,23.084,22.037z'fill=#26B999 /></g></svg>";
  ptr += "</div>";
  ptr += "<div class='side-by-side text'>Pression</div>";
  ptr += "<div class='side-by-side reading'>";
  ptr += pressure;
  ptr += "<span class='superscript'>hPa</span></div>";
  ptr += "</div>";
  ptr += "<div class='data altitude'>";
  ptr += "<div class='side-by-side icon'>";
  ptr += "<svg enable-background='new 0 0 58.422 40.639'height=40.639px id=Layer_1 version=1.1 viewBox='0 0 58.422 40.639'width=58.422px x=0px xml:space=preserve xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink y=0px><g><path d='M58.203,37.754l0.007-0.004L42.09,9.935l-0.001,0.001c-0.356-0.543-0.969-0.902-1.667-0.902";
  ptr += "c-0.655,0-1.231,0.32-1.595,0.808l-0.011-0.007l-0.039,0.067c-0.021,0.03-0.035,0.063-0.054,0.094L22.78,37.692l0.008,0.004";
  ptr += "c-0.149,0.28-0.242,0.594-0.242,0.934c0,1.102,0.894,1.995,1.994,1.995v0.015h31.888c1.101,0,1.994-0.893,1.994-1.994";
  ptr += "C58.422,38.323,58.339,38.024,58.203,37.754z'fill=#955BA5 /><path d='M19.704,38.674l-0.013-0.004l13.544-23.522L25.13,1.156l-0.002,0.001C24.671,0.459,23.885,0,22.985,0";
  ptr += "c-0.84,0-1.582,0.41-2.051,1.038l-0.016-0.01L20.87,1.114c-0.025,0.039-0.046,0.082-0.068,0.124L0.299,36.851l0.013,0.004";
  ptr += "C0.117,37.215,0,37.62,0,38.059c0,1.412,1.147,2.565,2.565,2.565v0.015h16.989c-0.091-0.256-0.149-0.526-0.149-0.813";
  ptr += "C19.405,39.407,19.518,39.019,19.704,38.674z'fill=#955BA5 /></g></svg>";
  ptr += "</div>";
  ptr += "<div class='side-by-side text'>Altitude</div>";
  ptr += "<div class='side-by-side reading'>";
  ptr += altitude;
  ptr += "<span class='superscript'>m</span></div>";
  ptr += "</div>";
  ptr += "<div class='data altIGN'>";
  ptr += "<div class='side-by-side icon'>";
  ptr += "<svg enable-background='new 0 0 58.422 40.639'height=40.639px id=Layer_1 version=1.1 viewBox='0 0 58.422 40.639'width=58.422px x=0px xml:space=preserve xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink y=0px><g><path d='M58.203,37.754l0.007-0.004L42.09,9.935l-0.001,0.001c-0.356-0.543-0.969-0.902-1.667-0.902";
  ptr += "c-0.655,0-1.231,0.32-1.595,0.808l-0.011-0.007l-0.039,0.067c-0.021,0.03-0.035,0.063-0.054,0.094L22.78,37.692l0.008,0.004";
  ptr += "c-0.149,0.28-0.242,0.594-0.242,0.934c0,1.102,0.894,1.995,1.994,1.995v0.015h31.888c1.101,0,1.994-0.893,1.994-1.994";
  ptr += "C58.422,38.323,58.339,38.024,58.203,37.754z'fill=#955BA5 /><path d='M19.704,38.674l-0.013-0.004l13.544-23.522L25.13,1.156l-0.002,0.001C24.671,0.459,23.885,0,22.985,0";
  ptr += "c-0.84,0-1.582,0.41-2.051,1.038l-0.016-0.01L20.87,1.114c-0.025,0.039-0.046,0.082-0.068,0.124L0.299,36.851l0.013,0.004";
  ptr += "C0.117,37.215,0,37.62,0,38.059c0,1.412,1.147,2.565,2.565,2.565v0.015h16.989c-0.091-0.256-0.149-0.526-0.149-0.813";
  ptr += "C19.405,39.407,19.518,39.019,19.704,38.674z'fill=#955BA5 /></g></svg>";
  ptr += "</div>";
  ptr += "<div class='side-by-side text'>Altitude corrig&eacute;e</div>";
  ptr += "<div class='side-by-side reading'>";
  ptr += altIGN;
  ptr += "<span class='superscript'>m</span></div>";
  ptr += "</div>";
  ptr += "<div class='data pnmm'>";
  ptr += "<div class='side-by-side icon'>";
  ptr += "<svg enable-background='new 0 0 40.542 40.541'height=40.541px id=Layer_1 version=1.1 viewBox='0 0 40.542 40.541'width=40.542px x=0px xml:space=preserve xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink y=0px><g><path d='M34.313,20.271c0-0.552,0.447-1,1-1h5.178c-0.236-4.841-2.163-9.228-5.214-12.593l-3.425,3.424";
  ptr += "c-0.195,0.195-0.451,0.293-0.707,0.293s-0.512-0.098-0.707-0.293c-0.391-0.391-0.391-1.023,0-1.414l3.425-3.424";
  ptr += "c-3.375-3.059-7.776-4.987-12.634-5.215c0.015,0.067,0.041,0.13,0.041,0.202v4.687c0,0.552-0.447,1-1,1s-1-0.448-1-1V0.25";
  ptr += "c0-0.071,0.026-0.134,0.041-0.202C14.39,0.279,9.936,2.256,6.544,5.385l3.576,3.577c0.391,0.391,0.391,1.024,0,1.414";
  ptr += "c-0.195,0.195-0.451,0.293-0.707,0.293s-0.512-0.098-0.707-0.293L5.142,6.812c-2.98,3.348-4.858,7.682-5.092,12.459h4.804";
  ptr += "c0.552,0,1,0.448,1,1s-0.448,1-1,1H0.05c0.525,10.728,9.362,19.271,20.22,19.271c10.857,0,19.696-8.543,20.22-19.271h-5.178";
  ptr += "C34.76,21.271,34.313,20.823,34.313,20.271z M23.084,22.037c-0.559,1.561-2.274,2.372-3.833,1.814";
  ptr += "c-1.561-0.557-2.373-2.272-1.815-3.833c0.372-1.041,1.263-1.737,2.277-1.928L25.2,7.202L22.497,19.05";
  ptr += "C23.196,19.843,23.464,20.973,23.084,22.037z'fill=#26B999 /></g></svg>";
  ptr += "</div>";
  ptr += "<div class='side-by-side text'>Pression NMM</div>";
  ptr += "<div class='side-by-side reading'>";
  ptr += pnmm;
  ptr += "<span class='superscript'>hPa</span></div>";
  ptr += "</div>";
  ptr += "</div>";
  ptr += "</body>";
  ptr += "</html>";
  return ptr;
}

Did you get an example program using just the display and touch working ?

Yes
For example this code works

#include <SPI.h>
#include <TFT_eSPI.h>      // Hardware-specific library

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library

#define TFT_GREY 0x3186 // New colour
#define TFT_TOMATE 0xD942
#define TFT_JADE 0x8752
#define TFT_ANIS 0x9F4A

#define font 1

uint16_t x = 0, y = 0; // To store the touch coordinates

void setup() {
  // Initialise the TFT screen
  tft.init();
  Serial.begin(115200);
  // Use this calibration code in setup():
  uint16_t calData[5] = { 496, 3380, 389, 3372, 3 };
  tft.setTouch(calData);

  tft.setRotation(3);

  tft.fillScreen(TFT_GREY);

  tft.fillRect(20, 170, 70, 50, TFT_JADE);
  tft.fillRect(230, 170, 70, 50, TFT_TOMATE);


}

void loop() {
  // put your main code here, to run repeatedly:
  boolean pressed = tft.getTouch(&x, &y);

  //si tft.setRotation(1);
/*
  if (pressed)
  {
    if ((x >= 20 && x <= 70) && (y >= 170 && y <= 220))
    {
      tft.fillRect(135, 20, 70, 50, TFT_JADE);
    }
    if ((x >= 230 && x <= 300) && (y >= 170 && y <= 220))
    {
      tft.fillRect(135, 20, 70, 50, TFT_GREY);
    }
  }
*/
  //si tft.setRotation(3);
  if (pressed) 
  {
    Serial.print("x = "); Serial.println(x);
    Serial.print("y = "); Serial.println(y);
    if ((x >= 230 && x <= 300) && (y >= 20 && y <= 70))
    {
      tft.fillRect(135, 20, 70, 50, TFT_JADE);
    }
    if ((x >= 20 && x <= 90) && (y >=20 && y <= 70))
    {
      tft.fillRect(135, 20, 70, 50, TFT_GREY);
    }
  }

}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.