Ecran tft tactile

Bonjour,
Nouveau problème...
je souhaite utiliser une interruption pour vérifier périodiquement le les cordonnées d'une éventuelle pression sur le tactile.

j'ai donc fais un programme simple dans un premier temps, pour tester le tactile avec l’interruption. Ça fonctionne, quant on touche l'écran les boutons apparaissent, quant on touche un bouton, il disparaissent.

// Paint example specifically for the TFTLCD breakout board.
// If using the Arduino shield, use the tftpaint_shield.pde sketch instead!
// DOES NOT CURRENTLY WORK ON ARDUINO LEONARDO


#include <TimerOne.h>


#define periodeDeMesure 60000
long int heure = 0;
long int ancienneHeure = 0;


#include <Elegoo_GFX.h>    // Core graphics library
#include <Elegoo_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>

#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif

// 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).
//   D0 connects to digital pin 22
//   D1 connects to digital pin 23
//   D2 connects to digital pin 24
//   D3 connects to digital pin 25
//   D4 connects to digital pin 26
//   D5 connects to digital pin 27
//   D6 connects to digital pin 28
//   D7 connects to digital pin 29

// For the Arduino Due, use digital pins 33 through 40
// (on the 2-row header at the end of the board).
//   D0 connects to digital pin 33
//   D1 connects to digital pin 34
//   D2 connects to digital pin 35
//   D3 connects to digital pin 36
//   D4 connects to digital pin 37
//   D5 connects to digital pin 38
//   D6 connects to digital pin 39
//   D7 connects to digital pin 40

#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 9   // can be a digital pin
#define XP 8   // can be a digital pin

#define TS_MINX 105
#define TS_MINY 78
#define TS_MAXX 925
#define TS_MAXY 904

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET 0

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


Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;

void setup(void) {
  Serial.begin(9600);
  Serial.println(F("Paint!"));
Timer1.initialize(10000);
Timer1.attachInterrupt(clignoter);
pinMode (LED_BUILTIN, OUTPUT);  
  tft.reset();
  
  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 Elegoo 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_Elegoo_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Elegoo_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);

tft.setRotation(1);

  pinMode(13, OUTPUT);

}

#define MINPRESSURE 10
#define MAXPRESSURE 1000
 int X,Y,Z,Pression;
void loop()
{
Serial.println("loop");
  
delay(5000);

}
void clignoter(void)
{
  
     digitalWrite (LED_BUILTIN, !digitalRead(LED_BUILTIN));
      digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);






  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {

    
    // scale from 0->1023 to tft.width
    //p.x = tft.height()-map(p.x, TS_MINX, TS_MAXX, tft.height(), 0);
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.height(), 0);
    //p.y = (tft.width()-map(p.y, TS_MINY, TS_MAXY,  tft.width(), 0));
    p.y = map(p.y, TS_MINY, TS_MAXY, tft.width(), 0);
    
    X = p.y;
    Y = p.x;
    tft.drawPixel(X,Y,RED);
    if(Y < 30 && X < 320) return;
    for (int i = 0; i<=3; i++){
    tft.fillRoundRect(260, 45*i+35, 70, 20,8, BLUE);
  }
    tft.setTextColor(BLACK); 
    tft.setTextSize(1);
    tft.setCursor(270, 40);
    tft.println("CO2");
    tft.setCursor(270, 85);
    tft.println("TEMP");
    tft.setCursor(270, 130);
    tft.println("HR");
    tft.setCursor(270, 175);
    tft.println("COV");
    p.z=0;


      Serial.print("x:");
      Serial.println(X);
      Serial.print("y:");
      Serial.println(Y);



 

      tft.drawPixel(160+random(0,10),120+random(0,10),GREEN);
      
        if((X>260) && (X<340) && (Y>35) && (Y<80)){
        Serial.println(F("touch CO2"));
        tft.fillRect(250,35,70,180,BLACK);
        tft.fillScreen(BLACK);
      }
        if((X>260) && (X<340) && (Y>80) && (Y<125)){
        Serial.println(F("touch temp"));
        tft.fillRect(250,35,70,180,BLACK);
        tft.fillScreen(BLACK);
      }
        if((X>260) && (X<340) && (Y>125) && (Y<170)){
        Serial.println(F("touch hr"));
        tft.fillRect(250,35,70,180,BLACK);
        tft.fillScreen(BLACK);
      }
        if((X>260) && (X<340) && (Y>170) && (Y<215)){
        Serial.println(F("touch cov"));
        tft.fillRect(250,35,70,180,BLACK);
        tft.fillScreen(BLACK);
      }
    }
     }
     


le problème est quant on veut faire la mesure de manière periodique et l'affichage des boutons dans deux modes différents : on teste périodiquement l'écran, et à chaque tour de loop on s'occupe de l'affichage. et la plus rien ne marche...

// Paint example specifically for the TFTLCD breakout board.
// If using the Arduino shield, use the tftpaint_shield.pde sketch instead!
// DOES NOT CURRENTLY WORK ON ARDUINO LEONARDO


#include <TimerOne.h>


#define periodeDeMesure 60000
long int heure = 0;
long int ancienneHeure = 0;


#include <Elegoo_GFX.h>    // Core graphics library
#include <Elegoo_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>

#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif

// 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).
//   D0 connects to digital pin 22
//   D1 connects to digital pin 23
//   D2 connects to digital pin 24
//   D3 connects to digital pin 25
//   D4 connects to digital pin 26
//   D5 connects to digital pin 27
//   D6 connects to digital pin 28
//   D7 connects to digital pin 29

// For the Arduino Due, use digital pins 33 through 40
// (on the 2-row header at the end of the board).
//   D0 connects to digital pin 33
//   D1 connects to digital pin 34
//   D2 connects to digital pin 35
//   D3 connects to digital pin 36
//   D4 connects to digital pin 37
//   D5 connects to digital pin 38
//   D6 connects to digital pin 39
//   D7 connects to digital pin 40

#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 9   // can be a digital pin
#define XP 8   // can be a digital pin

#define TS_MINX 105
#define TS_MINY 78
#define TS_MAXX 925
#define TS_MAXY 904

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET 0

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


Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;

void setup(void) {
  Serial.begin(9600);
  Serial.println(F("Paint!"));
Timer1.initialize(10000);
Timer1.attachInterrupt(clignoter);
pinMode (LED_BUILTIN, OUTPUT);  
  tft.reset();
  
  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 Elegoo 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_Elegoo_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Elegoo_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);

tft.setRotation(1);

  pinMode(13, OUTPUT);

}

#define MINPRESSURE 10
#define MAXPRESSURE 1000
 int X,Y,Z,Pression;
void loop()
{
Serial.println("loop");
  
delay(1000);
boutons();

}
void clignoter(void)
{
  
     digitalWrite (LED_BUILTIN, !digitalRead(LED_BUILTIN));
      digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);
      // scale from 0->1023 to tft.width
    //p.x = tft.height()-map(p.x, TS_MINX, TS_MAXX, tft.height(), 0);
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.height(), 0);
    //p.y = (tft.width()-map(p.y, TS_MINY, TS_MAXY,  tft.width(), 0));
    p.y = map(p.y, TS_MINY, TS_MAXY, tft.width(), 0);
    
    X = p.y;
    Y = p.x;
    Z = p.z;







     }

     void boutons(){
        if (Z > MINPRESSURE && Z < MAXPRESSURE) {

    

    tft.drawPixel(X,Y,RED);
    if(Y < 30 && X < 320) return;
    for (int i = 0; i<=3; i++){
    tft.fillRoundRect(260, 45*i+35, 70, 20,8, BLUE);
  }
    tft.setTextColor(BLACK); 
    tft.setTextSize(1);
    tft.setCursor(270, 40);
    tft.println("CO2");
    tft.setCursor(270, 85);
    tft.println("TEMP");
    tft.setCursor(270, 130);
    tft.println("HR");
    tft.setCursor(270, 175);
    tft.println("COV");
    


      Serial.print("x:");
      Serial.println(X);
      Serial.print("y:");
      Serial.println(Y);



 

      tft.drawPixel(160+random(0,10),120+random(0,10),GREEN);
      
        if((X>260) && (X<340) && (Y>35) && (Y<80)){
        Serial.println(F("touch CO2"));
        tft.fillRect(250,35,70,180,BLACK);
        tft.fillScreen(BLACK);
      }
        if((X>260) && (X<340) && (Y>80) && (Y<125)){
        Serial.println(F("touch temp"));
        tft.fillRect(250,35,70,180,BLACK);
        tft.fillScreen(BLACK);
      }
        if((X>260) && (X<340) && (Y>125) && (Y<170)){
        Serial.println(F("touch hr"));
        tft.fillRect(250,35,70,180,BLACK);
        tft.fillScreen(BLACK);
      }
        if((X>260) && (X<340) && (Y>170) && (Y<215)){
        Serial.println(F("touch cov"));
        tft.fillRect(250,35,70,180,BLACK);
        tft.fillScreen(BLACK);
      }
    }
     }


Si vous avez une idée?

Peux-tu expliquer plus précisément ce qui ne va pas ? Qu'est-ce qui se passe, ou ne se passe pas, dans le second code ?

Le plupart des écrans tactiles génèrent une interruption lorsqu'on appui cela décharge le micro de tout un tas de tests inutiles.
edit: il semble que ton écran ne possède pas de gestionnaire de la partie tactile et que ce soit fait directement par le micro. Donc ma remarque ne s'applique pas.

Il faut faire attention que la période de mesure ne soit pas plus courte que le temps de rafraîchissement de l'écran. Ou alors il faut désactiver les IT pendant que tu redessines l'écran.

Bonjour, merci pour vos réponses, je n’avais pas vu vos messages (pas de notification par mail).
N’arrivant pas à gérer les test du tactile avec les interruptions, j'ai opté pour une variable heure = millis();
Et je test si la valeur de heure est supérieur à une durée spécifiée, je stock heure dans une autre variable ancienneHeure pour le prochain tour de loop.

ça fonctionne. Merci tout de même pour votre temps et vos réponses.