Bonjour,
Je suis en train d'essayer de crée d'ouvrir une nouvelle page quand je clique à un endroit sur mon écran tft.
J'utilise un esp32 et un écran tft Adafruit TFT FeatherWing - 3.5" 480x320 Touchscreen.
J'ai vu un sujet similaire sur un autre écran donc j'ai essayé de l'adapté à mes librairies mais je n'y arrive pas donc je compte sur vous ![]()
Le "tuto" que je suis : Menu pour écran TFT - International / Français - Arduino Forum
Voici mon programme, c'est la partie avec my touch que je dois modifier mais je n'y arrive pas
#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_HX8357.h>
#include <Adafruit_STMPE610.h>
#ifdef ESP32
#define STMPE_CS 32
#define TFT_CS 15
#define TFT_DC 33
#define SD_CS 14
#endif
#define TFT_RST -1
// Use hardware SPI and the above for CS/DC
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
byte selecteurPage=0;
// on defini la fonction testTouche qui est definie en bolean donc elle renvoie une variable de type booleene donc soit faux : false soit vrai: true:
boolean TestTouche( int zoneX, int zoneY,int Longueur,int hauteur)
{
int X, Y,testX,testY;
boolean reponse=false;
if (myTouch.dataAvailable())// dataAvailable() est une fonction de la lib Utouch.h
{
myTouch.read();// read() est une fonction de la lib Utouch.h
X=myTouch.getX(), Y=myTouch.getY();// getX et getY() sont des fonction de la lib Utouch.h
//---- vérifie si appui sur la touche "+" ---------
testX=abs(X-(zoneX+Longueur/2)); // calcul valeur absolue de l'écart de X touchpad à ZoneX centre trouche
testY=abs(Y-(zoneY+hauteur/2)); // calcul valeur absolue de l'écart de Y touchpad à ZoneY centre trouche
if (testX<Longueur/2 && testY<hauteur/2)
{reponse= true;}
else
{reponse=false;}
}
return reponse;
}
void setup()
{
Serial.begin(115200);
Serial.println("HX8357D Test!");
tft.begin();
// read diagnostics (optional but can help debug problems)
uint8_t x = tft.readcommand8(HX8357_RDPOWMODE);
Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(HX8357_RDMADCTL);
Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(HX8357_RDCOLMOD);
Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(HX8357_RDDIM);
Serial.print("Image Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(HX8357_RDDSDR);
Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
Serial.println(F("Benchmark Time (microseconds)"));
Serial.println(F("Done!"));
}
void loop()
{
switch(selecteurPage){
case 1:
Home();
break;
case 2:
page_2();
break;
default:
Home();
break;
}
}
void Home(){
//Affichage de la page d'accueil
if (TestTouche(15, 15,150,15)){selecteurPage =2;}
tft.setCursor(25,225);
tft.setTextColor(HX8357_BLUE);
tft.setTextSize(3);
tft.println("Temp:");
tft.setCursor(25, 250);
tft.setTextColor(HX8357_BLUE);
tft.setTextSize(3);
tft.println("test");
}
}
void page_2(){
//Affichage des donne de la page3
if (TestTouche(30, 45,150,45)){selecteurPage =1;}
tft.setCursor(25,225);
tft.setTextColor(HX8357_BLUE);
tft.setTextSize(3);
tft.println("page3:");
tft.setCursor(25, 250);
tft.setTextColor(HX8357_BLUE);
tft.setTextSize(3);
tft.println("test");
}