Bonjour
Je teste un TFT touchscreen chinois avec la librairie Adafruit, et j'ai pu le faire fonctionner en graphique (tracer une courbe sur l'écran) et en touchscreen (afficher les coordonnées du point touché).
Je veux rassembler les deux fonctions, en ajoutant des "boutons" avec lesquels je pourrai changer la courbe tracée par exemple. Les boutons sont des carrés de couleur, ils s'affichent bien sur l'écran. Je veux ajouter des numéros sur les boutons. Et là, ça ne marche pas.
Pourtant, l'exemple de la librairie, qui affiche du texte, fonctionne parfaitement.
Je ne vois vraiment pas ce que j'ai loupé...
Voici mon programme, il n'est pas très gros :
#include <Adafruit_GFX_AS.h> // Core graphics library
#include <Adafruit_ILI9341_AS.h> // Hardware-specific library
#include <XPT2046_Touchscreen.h> // Touch
#include <SPI.h> // SPI libray obviously!
// Use hardware SPI lines
#define _sclk 13
#define _miso 12 // Needed for SD card, but does not need to be connected to TFT
#define _mosi 11 // Master Out Slave In to send commands/data to TFT and SD card
// TFT chip select and data/command line
#define _cs 10
#define _dc 9
// TFT reset line, can be connected to Arduino reset
#define _rst 7
// Touch
#define CS_PIN 8
#define TIRQ_PIN 2
Adafruit_ILI9341_AS tft = Adafruit_ILI9341_AS(_cs, _dc, _rst); // Invoke custom library
XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN); // Param 2 - Touch IRQ Pin - interrupt enabled polling
// Couleurs
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
uint16_t couleur = 1;
void setup() {
tft.init(); // Initialise the display (various parameters configured)
tft.setRotation(3); // Landscape mode
// Set font foreground and background colours
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.fillScreen(WHITE);
Serial.begin(9600);
// Init touchscreen
ts.begin();
while (!Serial && (millis() <= 1000));
// Affichage des boutons
tft.fillRect (0, 0,40,40,BLUE);
tft.fillRect (0,40,40,40,RED);
tft.fillRect (0,80,40,40,GREEN);
tft.fillRect (0,120,40,40,YELLOW);
tft.fillRect (0,160,40,40,MAGENTA);
tft.fillRect (0,200,40,40,CYAN);
// Textes sur les boutons
// C'est ici que ca ne fonctionne pas !!!
tft.setTextColor (BLACK);
tft.setTextSize (3);
for (int i=1;i<7;i++) {
tft.setCursor(20,(i-1)*40+20);
tft.println(i); }
}
void loop()
{
uint16_t x;
uint16_t y;
int num = 1;
tft.setCursor(100,100);
tft.println("GROOT!");
for (int j=0; j<10; j++) {
float a = (j+1)/10.;
courbe (x,y,0,a);
for (int i=0; i<361; i++) {
float t = i*2*3.14915926/360;
uint16_t xprev = x;
uint16_t yprev = y;
courbe (x,y,t,a);
tft.drawLine (xprev,yprev,x,y,couleur);
couleur = couleur + 50;
delay(10);
}
}
}
void courbe (uint16_t& xi, uint16_t& yi, float t, float a) {
//
float x = cos(2*t)+sin(3*t);
float y = sin(2*t)+cos(t);
xi = (unsigned int) (map (a*x*100,-200,200,50,320));
yi = (unsigned int) (map (a*y*100,-200,200,0,240));
}
Quelqu'un a une idée ? Merci...