#include <Arduino.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <XPT2046_Touchscreen.h>
#include <SPI.h>
#include <SoftwareSerial.h>
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// you can enable debug logging to Serial at 115200
//#define REMOTEXY__DEBUGLOG
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__HARDSERIAL
HardwareSerial Serial1(PC11, PC10); // RX, TX
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial1
#define REMOTEXY_SERIAL_SPEED 9600
#include <RemoteXY.h>
// RemoteXY GUI configuration
#pragma pack(push, 1)
uint8_t const PROGMEM RemoteXY_CONF_PROGMEM[] = // 99 bytes V19
{ 255,4,0,4,0,92,0,19,0,0,0,0,25,2,106,200,200,84,1,1,
5,0,1,17,29,40,32,3,17,96,31,7,121,31,0,1,18,33,40,31,
3,50,96,33,7,95,31,0,1,19,38,40,31,101,17,95,31,7,37,31,
0,1,20,43,40,31,101,50,95,33,7,191,31,0,73,45,31,7,76,152,
4,39,11,1,0,2,37,0,0,0,0,0,0,64,64,0,0,0,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
uint8_t B_VERT; // =1 if button pressed, else =0, from 0 to 1
uint8_t B_JAUNE; // =1 if button pressed, else =0, from 0 to 1
uint8_t B_ROUGE; // =1 if button pressed, else =0, from 0 to 1
uint8_t B_BLEU; // =1 if button pressed, else =0, from 0 to 1
// output variables
float COEURS; // from 0 to 3
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define TOUCH_CS 7
#define NOIR 0x0000
#define BLEU 0x001F
#define VERT 0x07E0
#define CYAN 0x07FF
#define ROUGE 0xF800
#define MAGENTA 0xF81F
#define ORANGE 0xFBA0
#define JAUNE 0xFFE0
#define BLANC 0xFFFF
#define TS_MINX 300 // pression min à x
#define TS_MAXX 3800
#define TS_MINY 300
#define TS_MAXY 3800
#define MAX_SEQUENCE 50
// Section Constantes
int SEQUENCE[MAX_SEQUENCE];
int LONGUEURSEQUENCE = 0;
// Section Sous-Programmes
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
XPT2046_Touchscreen ts = XPT2046_Touchscreen(TOUCH_CS);
int score = 0;
bool etaitTouche = false;
float coeurs = 3;
void afficherScore(){
tft.fillRect(90,5,140,30, NOIR);
tft.setCursor(15,10);
tft.setTextColor(BLANC);
tft.setTextSize(2);
tft.print("Score : ");
tft.print(score);
}
void afficherCoeurs(){
tft.fillRect(240, 0, 80, 30, NOIR);
for (int i = 0; i<3; i++){
int x = 250 + (i*22);
int y = 10;
tft.fillRect(x + 1, y, 5, 4, ROUGE);
tft.fillRect(x + 7, y, 5, 4, ROUGE);
tft.fillTriangle(x, y + 4, x + 12, y + 4, x + 6, y + 16, ROUGE);
// tft.fillRect(x, y + 2, 12, 3, ROUGE);
// tft.fillRect(x + 1, y + 5, 10, 2, ROUGE);
// tft.fillRect(x + 2, y + 7, 8, 2, ROUGE);
// tft.fillRect(x + 3, y + 9, 6, 2, ROUGE);
// tft.fillRect(x + 4, y + 11, 4, 2, ROUGE);
// tft.fillRect(x + 5, y + 13, 2, 2, ROUGE);
}
}
void dessinerBoutons() {
tft.fillRect(15, 45, 145, 85, VERT);
tft.fillRect(170, 45, 145, 85, ROUGE);
tft.fillRect(15, 140, 145, 85, JAUNE);
tft.fillRect(170, 140, 145, 85, BLEU);
}
void incrementerscore() {
if (!ts.touched()) {
etaitTouche = false;
return;
}
if (etaitTouche) return;
etaitTouche = true;
TS_Point p = ts.getPoint();
int pixelX = map(p.x, TS_MINX, TS_MAXX, 320, 0);
int pixelY = map(p.y, TS_MINY, TS_MAXY, 240, 0);
if (pixelX >= 15 && pixelX <= 160 && pixelY >= 45 && pixelY <= 130) {
tft.drawRect(15, 45, 145, 85, BLANC);
score++;
afficherScore();
delay(150);
tft.fillRect(15, 45, 145, 85, VERT);
}
else if (pixelX >= 170 && pixelX <= 315 && pixelY >= 45 && pixelY <= 130) {
tft.drawRect(170, 45, 145, 85, BLANC);
score++;
afficherScore();
delay(150);
tft.fillRect(170, 45, 145, 85, ROUGE);
}
else if (pixelX >= 15 && pixelX <= 160 && pixelY >= 140 && pixelY <= 225) {
tft.drawRect(15, 140, 145, 85, BLANC);
score++;
afficherScore();
delay(150);
tft.fillRect(15, 140, 145, 85, JAUNE);
}
else if (pixelX >= 170 && pixelX <= 315 && pixelY >= 140 && pixelY <= 225) {
tft.drawRect(170, 140, 145, 85, BLANC);
score++;
afficherScore();
delay(150);
tft.fillRect(170, 140, 145, 85, BLEU);
}
}
void creerSequence() {
if (LONGUEURSEQUENCE < MAX_SEQUENCE) {
SEQUENCE[LONGUEURSEQUENCE] = random(0, 4);
LONGUEURSEQUENCE++;
}
}
void setup() {
//remoteXY
RemoteXY_Init();
Serial.begin(115200);
tft.begin(40000000);
tft.setRotation(1);
tft.fillScreen(NOIR);
ts.begin();
ts.setRotation(1);
afficherScore();
afficherCoeurs();
dessinerBoutons();
randomSeed(analogRead(A0));
creerSequence();
}
void loop(){
incrementerscore();
//remoteXY
RemoteXYEngine.handler ();
RemoteXY.COEURS = coeurs;
if (RemoteXY.B_JAUNE)
{
coeurs -=1;
}
}
Comments