le code en entier
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_RA8875.h"
// Library only supports hardware SPI at this time
// Connect SCLK to UNO Digital #13 (Hardware SPI clock)
// Connect MISO to UNO Digital #12 (Hardware SPI MISO)
// Connect MOSI to UNO Digital #11 (Hardware SPI MOSI)
#define RA8875_INT 3
#define RA8875_CS 10
#define RA8875_RESET 9
Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);
uint16_t tx, ty;
int i =0;
int j =0;
int hauteur_case=96;
int largeur_case=200;
int texte_vertical = 96;
char outputbuffer[20]= { '\0' };
// couleurs des afficheurs de chaque piste
int couleur[4] = {RA8875_RED, RA8875_YELLOW, RA8875_CYAN, RA8875_GREEN};
int piste [4]= {1,2,3,4};
char racechar [6];
float race [5][4] {
{1,2,3,4}, // classement
{4,2,1,3}, // numero des pistes
{5.022, 6.543, 8.876, 9.644}, // chrono
{0, 1.521, 3.854, 4.622}, // ecart
{645, 630,520,450}, // vitesse
} ;
void setup()
{
Serial.begin(9600);
Serial.println("RA8875 start");
/* Initialize the display using 'RA8875_480x80', 'RA8875_480x128', 'RA8875_480x272' or 'RA8875_800x480' */
if (!tft.begin(RA8875_800x480)) {
Serial.println("RA8875 Not Found!");
while (1);
}
tft.displayOn(true);
tft.GPIOX(true); // Enable TFT - display enable tied to GPIOX
tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
tft.PWM1out(255);
tft.fillScreen(RA8875_WHITE);
/* Switch to text mode */
tft.textMode();
tft.cursorBlink(32);
}
void loop()
{
tft.textTransparent(RA8875_BLACK);
tft.textEnlarge(2);
char string[15] = "POS.";
char string1[15] = "TRACK";
char string2[15] = "TIME";
char string3[15] = "SPEED";
tft.textSetCursor(60, 24);
tft.textWrite(string);
tft.textSetCursor(195, 24);
tft.textWrite(string1);
tft.textSetCursor(370, 24);
tft.textWrite(string2);
tft.textSetCursor(600, 24);
tft.textWrite(string3);
//LIGNE
tft.drawLine(0, 96, 800, 96, RA8875_BLACK);
tft.drawLine(0, 192, 800, 192, RA8875_BLACK);
tft.drawLine(0, 288, 800, 288, RA8875_BLACK);
tft.drawLine(0, 384, 800, 384, RA8875_BLACK);
// COLONNE
tft.drawLine(185, 20, 185, 480, RA8875_BLACK);
tft.drawLine(325, 20, 325, 480, RA8875_BLACK);
tft.drawLine(520, 20, 520, 480, RA8875_BLACK);
/*for (i=0;i<5;i++) // creation des lignes et colonnes
{
tft.drawLine(20, hauteur_case*i, 800, hauteur_case*i, RA8875_BLACK);
tft.drawLine(largeur_case*i, 20, largeur_case*i, 480, RA8875_BLACK);
}*/
for (j =0; j<4;j++) // j permet de passer d'une voiture a une autre et de passer a la ligne suivante sur l'ecran
{
for (i=0; i<1;i++) // i permet d ecrire les données d'une voiture horizontalement à l'ecran
{
// faire un if si race 0/j est nul alors la voiture n est pas arrivée et donc ecire qquelque chose
// AFFICHAGE RESULT
if (race[i][j] == 1)
{ // voiture gagnante
tft.textTransparent(RA8875_RED);
tft.textEnlarge(2);
tft.textSetCursor(20,124);
tft.textWrite("WINNER");
}
else
{ // sinon afficher la place de la voiture
tft.textTransparent(RA8875_BLACK);
tft.textEnlarge(2);
tft.textSetCursor(55,120+(j*texte_vertical));
dtostrf(race[i][j], 2, 0, racechar);
tft.textWrite(racechar);
}
// AFFICHAGE TRACK avec CARRE DE LA COULEUR DE LA PISTE
for (int k=0; k<4; k++)
{
if (race[i+1][j] == piste [k])
{ tft.fillRect(185,(race[0][j]*96),140, 96, couleur[k]); }}
tft.textTransparent(RA8875_BLACK);
tft.textEnlarge(2);
tft.textSetCursor(240,120+(j*texte_vertical));
dtostrf(race[i+1][j], 1, 0, racechar);
tft.textWrite(racechar);
// AFFICHAGE CHRONO
tft.textTransparent(RA8875_BLACK);
tft.textEnlarge(2);
tft.textSetCursor(340,120+(j*texte_vertical));
if (race[i] [j] !=1)
{// si ce n'est pas la voiture gagnante, alors afficher l'ecart
dtostrf(race[i+3] [j], 5, 3, racechar);
snprintf(outputbuffer,15, "+%ss", racechar);
tft.textWrite(outputbuffer);
}
else
{ // afficher chrono de la premiere voiture
dtostrf(race[i+2] [j], 5, 3, racechar);
snprintf(outputbuffer,15, "%ss", racechar);
tft.textWrite(outputbuffer);
}
// AFFICHAGE VITESSE
tft.textTransparent(RA8875_BLACK);
tft.textEnlarge(2);
tft.textSetCursor(540,120+(j*texte_vertical));
dtostrf(race[i+4] [j], 5, 1, racechar);
snprintf(outputbuffer,15, "%s km/h", racechar);
tft.textWrite(outputbuffer);
}
}
}
