Bonjour,
J'aimerais créer plusieurs page sur mon écran tft.
voici mon écran : Adafruit TFT FeatherWing - 3.5 480x320 Touchscreen for Feathers : ID 3651 : $39.95 : Adafruit Industries, Unique & fun DIY electronics and kits
J'utilise la librairie adafruit GFX
J'aimerais savoir si quelqu'un aurait un programme exemple, pour que je puisse essayer de comprendre comment ça marche . du style quand je clic en en bas à gauche ça m'ouvre une nouvelle page bleu par exemple.
Tous les exemples que j'ai trouvé était avec la libraire utft et urtouch qui ne sont pas compatible avec mon écran .
Vous remerciant
vous avez regardez les exemples d'Adafruit?
Il n'y a pas d'exemple qui montre différentes pages la dessus il me semble .
@lesept tu n'y connais pas toi ?
"différentes pages" ça ne veut rien dire vraiment. Vous effacez l'écran et peignez quelque chose d'autre.
Du style if je clic en bas à gauche ça efface tous puis m'affiche les températures des 8 dernières heures ?
Je vais essayer alors ![]()
ben oui ![]()
Par hasard tu sais ou je pourrais trouver les commandes qui vont avec la librairie #include <Adafruit_STMPE610.h> car j'ai réussi à le faire mais j'aimerais que ça se passe que lorsque je clic dans une zone que j'ai défini.
j'ai regardé ici mais rien n'est indiquer. Resistive Touch Screen | Adafruit 3.5" 480x320 TFT FeatherWing | Adafruit Learning System
if ( ts.touched()), j'ai essayer de mettre x,y, longueur , hauteur mais ça ne fonctionne pas
if ( ts.touched())
{
// ON EFFACE
tft.setCursor(0, 25);
tft.setTextColor(HX8357_WHITE);
tft.println("Coucou");
// ON MET AUTRE CHOSE
tft.setCursor(0, 25);
tft.setTextColor(HX8357_BLUE);
tft.println("C'est nous");
return;
}
}
le fichier est là:
Adafruit_STMPE610/Adafruit_STMPE610.h at master · adafruit/Adafruit_STMPE610 · GitHub et les méthodes publiques utilitaires:
Il y a surtout l'exemples de la librairie qui lit les coordonnées de la zone touchée et les affiches.
Je viens de regarder mais je comprendre pas trop , je dois mettre / faire quoi ?
@fdufnews ce programme exemple ?
/***************************************************
This is our library for the Adafruit HX8357D Featherwing
----> http://www.adafruit.com/products/2050
Check out the links above for our tutorials and wiring diagrams
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_HX8357.h>
#include <Adafruit_STMPE610.h>
#ifdef ESP8266
#define STMPE_CS 16
#define TFT_CS 0
#define TFT_DC 15
#define SD_CS 2
#endif
#ifdef ESP32
#define STMPE_CS 32
#define TFT_CS 15
#define TFT_DC 33
#define SD_CS 14
#endif
#ifdef TEENSYDUINO
#define TFT_DC 10
#define TFT_CS 4
#define STMPE_CS 3
#define SD_CS 8
#endif
#ifdef ARDUINO_STM32_FEATHER
#define TFT_DC PB4
#define TFT_CS PA15
#define STMPE_CS PC7
#define SD_CS PC5
#endif
#ifdef ARDUINO_NRF52832_FEATHER
#define STMPE_CS 30
#define TFT_CS 31
#define TFT_DC 11
#define SD_CS 27
#endif
#if defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR)
#define TFT_DC P5_4
#define TFT_CS P5_3
#define STMPE_CS P3_3
#define SD_CS P3_2
#endif
// Anything else!
#if defined (__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_FEATHER_M0) || defined (__AVR_ATmega328P__) || \
defined(ARDUINO_SAMD_ZERO) || defined(__SAMD51__) || defined(__SAM3X8E__) || defined(ARDUINO_NRF52840_FEATHER)
#define STMPE_CS 6
#define TFT_CS 9
#define TFT_DC 10
#define SD_CS 5
#endif
#define TFT_RST -1
// Init screen on hardware SPI, HX8357D type:
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 3800
#define TS_MAXX 100
#define TS_MINY 100
#define TS_MAXY 3750
// Size of the color selection boxes and the paintbrush size
#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;
void setup() {
Serial.begin(115200);
//while (!Serial) delay(10);
Serial.println("HX8357D Featherwing touch test!");
if (!ts.begin()) {
Serial.println("Couldn't start touchscreen controller");
while (1);
}
Serial.println("Touchscreen started");
tft.begin();
tft.fillScreen(HX8357_BLACK);
// make the color selection boxes
tft.fillRect(0, 0, BOXSIZE, BOXSIZE, HX8357_RED);
tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_YELLOW);
tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_GREEN);
tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_CYAN);
tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_BLUE);
tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_MAGENTA);
tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_BLACK);
tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_WHITE);
// select the current color 'red'
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, HX8357_WHITE);
currentcolor = HX8357_RED;
}
void loop(void) {
// Retrieve a point
TS_Point p = ts.getPoint();
// Serial.print("X = "); Serial.print(p.x); Serial.print("\tY = "); Serial.print(p.y); Serial.print("\tPressure = "); Serial.println(p.z);
// Scale from ~0->4000 to tft.width using the calibration #'s
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
if (p.y < BOXSIZE) {
oldcolor = currentcolor;
if (p.x < BOXSIZE) {
currentcolor = HX8357_RED;
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, HX8357_WHITE);
} else if (p.x < BOXSIZE*2) {
currentcolor = HX8357_YELLOW;
tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_WHITE);
} else if (p.x < BOXSIZE*3) {
currentcolor = HX8357_GREEN;
tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_WHITE);
} else if (p.x < BOXSIZE*4) {
currentcolor = HX8357_CYAN;
tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_WHITE);
} else if (p.x < BOXSIZE*5) {
currentcolor = HX8357_BLUE;
tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_WHITE);
} else if (p.x < BOXSIZE*6) {
currentcolor = HX8357_MAGENTA;
tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_WHITE);
} else if (p.x < BOXSIZE*7) {
currentcolor = HX8357_WHITE;
tft.drawRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_RED);
} else if (p.x < BOXSIZE*8) {
currentcolor = HX8357_BLACK;
tft.drawRect(BOXSIZE*7, 0, BOXSIZE, BOXSIZE, HX8357_WHITE);
}
if (oldcolor != currentcolor) {
if (oldcolor == HX8357_RED)
tft.fillRect(0, 0, BOXSIZE, BOXSIZE, HX8357_RED);
if (oldcolor == HX8357_YELLOW)
tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, HX8357_YELLOW);
if (oldcolor == HX8357_GREEN)
tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, HX8357_GREEN);
if (oldcolor == HX8357_CYAN)
tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, HX8357_CYAN);
if (oldcolor == HX8357_BLUE)
tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, HX8357_BLUE);
if (oldcolor == HX8357_MAGENTA)
tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, HX8357_MAGENTA);
if (oldcolor == HX8357_WHITE)
tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, HX8357_WHITE);
if (oldcolor == HX8357_BLACK)
tft.fillRect(BOXSIZE*7, 0, BOXSIZE, BOXSIZE, HX8357_BLACK);
}
}
if (((p.y-PENRADIUS) > 0) && ((p.y+PENRADIUS) < tft.height())) {
tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
}
}
A ma grande surprise j'ai réussi à faire un truc ![]()
mais j'ai du mal pour trouver l'endroit de mon carré, que siginie ça : if ( p.x>60 && p.x<260 && p.y>120 && p.y<180 && Clic){
Si j'ai bien compris px compris entre 60 et 260 et py compris entre 120 et 180 mais j'arrive pas trouver la zone que je veux, je pense que c'est à cause de ça :#define TS_MINX 3800
#define TS_MAXX 100
#define TS_MINY 100
#define TS_MAXY 3750
mais comment savoir quelles valeurs je dois mettre ? mon écran fait 480*320 pixels
#include <SPI.h>
#include "Adafruit_GFX.h"
#include <Fonts/FreeSerif18pt7b.h>
#include "Adafruit_HX8357.h"
#include <Adafruit_STMPE610.h>
#define STMPE_CS 32
#define TFT_CS 15
#define TFT_DC 33
#define SD_CS 14
#define TFT_RST -1
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
#define TS_MINX 3800
#define TS_MAXX 100
#define TS_MINY 100
#define TS_MAXY 3750
boolean Clic = true;
void setup() {
Serial.begin(115200);
//while (!Serial) delay(10);
Serial.println("HX8357D Featherwing touch test!");
if (!ts.begin()) {
Serial.println("Couldn't start touchscreen controller");
while (1);
}
Serial.println("Touchscreen started");
tft.begin();
tft.setRotation(1);
tft.fillScreen(HX8357_WHITE);
tft.setFont(&FreeSerif18pt7b);
tft.setTextColor(HX8357_BLUE, HX8357_WHITE);
// ON AFFICHE
tft.setCursor(0, 25);
tft.setTextColor(HX8357_BLUE);
tft.println("Coucou");
tft.fillRect(310,250,90,50,HX8357_BLACK); //(x,y,width,heigh,color)
}
void loop() {
TS_Point p = ts.getPoint();
p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);
p.y = map(p.y, TS_MINY, TS_MAXY, 0, 480);
if ( p.x>60 && p.x<260 && p.y>120 && p.y<180 && Clic){
Clic = false ;
// ON EFFACE
tft.setCursor(0, 25);
tft.setTextColor(HX8357_WHITE);
tft.println("Coucou");
// ON MET AUTRE CHOSE
tft.setCursor(0, 25);
tft.setTextColor(HX8357_BLUE);
tft.println("C'est nous");
return;
}
}
Non, je parle de ce programme TouchTest.ino qui est installé avec la librairie Adafruit_STMPE610. Il affiche dans la console les coordonnées des points touchés sur l'écran.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.