Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_GFX.h>
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_ILI9341.h>
- #include <Adafruit_STMPE610.h>
- #define TS_MINX 150
- #define TS_MINY 130
- #define TS_MAXX 3800
- #define TS_MAXY 4000
- #define STMPE_CS 8
- Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
- #define TFT_CS 10
- #define TFT_DC 9
- Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
- #define PressionMin 2
- #define PressionMax 1000
- unsigned long tempoPression = 0;
- //*********************************************************************
- #define BrocheDroite 22
- boolean etatBoutonDroite = false;
- boolean LastetatBoutonDroite = true;
- //*********************************************************************
- #define BrocheGauche 23
- boolean etatBoutonGauche = false;
- boolean LastetatBoutonGauche = true;
- void setup() {
- Serial.begin(9600);
- pinMode(BrocheDroite, OUTPUT);
- pinMode(BrocheGauche, OUTPUT);
- tft.begin();
- tft.setRotation(3);
- tft.fillScreen(ILI9341_WHITE);
- if (!ts.begin()) {
- while (1);
- }
- }
- void loop() {
- GestionTactile();
- GestionBouton();
- }
- //*********************************************************************
- //*** Fonction Gestion Bouton ***********************************************
- //********************************************************************************
- void GestionBouton(){
- if (LastetatBoutonDroite != etatBoutonDroite)
- {
- uint16_t coulBoutonDroite = ILI9341_GREEN;
- if (etatBoutonDroite) {coulBoutonDroite = ILI9341_BLUE;}
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(2);
- tft.fillRoundRect(225, 70, 85, 40, 12, coulBoutonDroite);
- tft.drawRoundRect(223, 68, 89, 44, 12, coulBoutonDroite);
- tft.setCursor(235, 85); tft.print(F("Droite"));
- LastetatBoutonDroite = etatBoutonDroite;
- }
- //*******************************************************************************
- if (LastetatBoutonGauche != etatBoutonGauche)
- {
- uint16_t coulBoutonGauche = ILI9341_RED;
- if (etatBoutonGauche) {coulBoutonGauche = ILI9341_BLUE;}
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(2);
- tft.fillRoundRect(15, 70, 85, 40, 12, coulBoutonGauche);
- tft.drawRoundRect(13, 68, 89, 44, 12, coulBoutonGauche);
- tft.setCursor(23, 85); tft.print(F("Gauche"));
- LastetatBoutonGauche = etatBoutonGauche;
- }
- }
- //*********************************************************************************
- //*** Fonction Gestion Tactile de l'écran TFT *************************************
- //*********************************************************************************
- void GestionTactile (){
- if (ts.bufferEmpty()) {
- return;
- }
- TS_Point p = ts.getPoint();
- p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
- p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
- Serial.print(p.x);
- Serial.print(" , ");
- Serial.println(p.y);
- //**********************************************************************************
- if (millis() - tempoPression >= 1000ul && tempoPression != 0 || tempoPression == 0)
- {
- if (p.x > 230 && p.x < 270 && p.y > 20 && p.y < 70) //Droite
- {
- etatBoutonDroite = !etatBoutonDroite;
- digitalWrite(BrocheDroite, etatBoutonDroite);
- }
- //**********************************************************************************
- if (p.x > 230 && p.x < 270 && p.y > 90 && p.y < 150) //Gauche
- {
- etatBoutonGauche = !etatBoutonGauche;
- digitalWrite(BrocheGauche, etatBoutonGauche);
- }
- tempoPression = millis();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement