Comment utiliser un ÉCRAN TACTILE avec un ARDUINO

Vidéo

Liste des Composants

Arduino – Amazon
Écran Tactile – Amazon

Les Librairies

Le Code Final

#include <Adafruit_TFTLCD.h> 
#include <Adafruit_GFX.h>    
#include <TouchScreen.h>

#define LCD_CS A3 
#define LCD_CD A2 
#define LCD_WR A1 
#define LCD_RD A0 
#define LCD_RESET A4 

#define TS_MINX 140
#define TS_MINY 184
#define TS_MAXX 912
#define TS_MAXY 863

#define YP A3
#define XM A2
#define YM 9
#define XP 8

#define BLANC   0xFFFF
#define NOIR    0x0000
#define BLEU    0x001F
#define CYAN    0x07FF
#define VERT    0x07E0
#define JAUNE   0xFFE0
#define ROUGE   0xF800
#define MAGENTA 0xF81F
#define ORANGE  0xF400

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

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 364);

boolean Clic = true;

void setup() {
  
  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  tft.setRotation(1);
   tft.fillScreen(NOIR);

  tft.fillRect(10, 10, 300, 220, ORANGE);
  tft.fillRect(20, 20, 280, 200, NOIR);
  tft.fillRect(30, 30, 260, 180, ORANGE);
  tft.fillRect(40, 40, 240, 160, NOIR);

  tft.setCursor(50, 50);
  tft.setTextColor(BLANC);
  tft.setTextSize(2);
  tft.print("  GammaTroniques  ");

  tft.setCursor(60, 80);
  tft.setTextColor(BLANC);
  tft.setTextSize(2);
  tft.print("gammatroniques.fr");

  tft.fillRect(60, 120, 200, 60, ROUGE);

  tft.setCursor(75, 135);
  tft.setTextColor(BLANC);
  tft.setTextSize(3);
  tft.print("S'ABONNER");

}

void loop() {
  TSPoint p = ts.getPoint();
  
  if (p.z > ts.pressureThreshhold) {
    
   p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
   p.y = map(p.y, TS_MAXY, TS_MINY, 0, 480);
       
   if(p.x>60 && p.x<260 && p.y>120 && p.y<180 && Clic){
    
    Clic = false;
    
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    
    tft.fillScreen(NOIR);
    tft.fillRect(80, 120, 180, 60, BLANC);
    tft.setCursor(115,140);
    tft.setTextColor(NOIR);
    tft.setTextSize(3);
    tft.print("ABONN");
    tft.print((char)144);

    tft.setCursor(90, 70);
    tft.setTextColor(ROUGE);
    tft.setTextSize(4);
    tft.print("Merci !");

   }  
  }
}