commit
41d4b12391
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1,65 @@
|
||||
//#include "TFT_eSPI.h"
|
||||
//#define R 5 //Rayon de la boule donc diamètre 10
|
||||
//#define XMAX 320
|
||||
//#define YMAX 240
|
||||
//
|
||||
//TFT_eSPI tft;
|
||||
//int x=XMAX/2,y=YMAX/2 ; //boule positionnée au milieu de l'écran
|
||||
//unsigned int modif=1 ; //si déplacement, on affiche. 1 pour premier affichage
|
||||
//
|
||||
//void setup() {
|
||||
// tft.begin();
|
||||
// tft.setRotation(3); // (0,0) à l'oppossé du joyssitck
|
||||
// tft.fillScreen(TFT_WHITE); // fond blanc
|
||||
//
|
||||
// pinMode(WIO_5S_UP, INPUT_PULLUP);
|
||||
// pinMode(WIO_5S_DOWN, INPUT_PULLUP);
|
||||
// pinMode(WIO_5S_LEFT, INPUT_PULLUP);
|
||||
// pinMode(WIO_5S_RIGHT, INPUT_PULLUP);
|
||||
//}
|
||||
//
|
||||
//void loop() {
|
||||
// if (digitalRead(WIO_5S_UP) == LOW) {
|
||||
// modif=1;
|
||||
// y--;
|
||||
// if (y < 0) {
|
||||
// tft.fillScreen(TFT_WHITE);
|
||||
// y=YMAX ;
|
||||
// }
|
||||
// }
|
||||
// else if (digitalRead(WIO_5S_DOWN) == LOW) {
|
||||
// modif=1;
|
||||
// y++;
|
||||
// if (y >= YMAX) {
|
||||
// tft.fillScreen(TFT_WHITE);
|
||||
// y=0 ;
|
||||
// }
|
||||
// }
|
||||
// else if (digitalRead(WIO_5S_LEFT) == LOW) {
|
||||
// modif=1;
|
||||
// x--;
|
||||
// if (x<0) {
|
||||
// tft.fillScreen(TFT_WHITE);
|
||||
// x=XMAX ;
|
||||
// }
|
||||
// }
|
||||
// else if (digitalRead(WIO_5S_RIGHT) == LOW) {
|
||||
// modif=1;
|
||||
// x++;
|
||||
// if (x >= XMAX) {
|
||||
// tft.fillScreen(TFT_WHITE);
|
||||
// x=0;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (modif == 1){
|
||||
// // remettre un fond blanc prend du temps (320x240 pixels à changer) l'affichage n'est plus fluide
|
||||
// // donc on efface le précédent avec un cercle blanc plus grand
|
||||
// tft.fillCircle(x,y,R + 1,TFT_WHITE);
|
||||
// // on affiche le nouveau cercle
|
||||
// tft.fillCircle(x,y, R, TFT_RED);
|
||||
// modif=0;
|
||||
// }
|
||||
// //le delay permet de régler la vitesse de déplacement
|
||||
// delay(20);
|
||||
//}
|
@ -0,0 +1,126 @@
|
||||
#include"LIS3DHTR.h"
|
||||
#include "TFT_eSPI.h"
|
||||
LIS3DHTR<TwoWire> lis;
|
||||
#define R 5 //Rayon de la boule donc diamètre 10
|
||||
#define XMAX 240 // Définit la taille en longueur de l'écran
|
||||
#define YMAX 320 // Définit la taille en largeur de l'écran
|
||||
|
||||
TFT_eSPI tft;
|
||||
unsigned int modif=1 ; //si déplacement, on affiche. 1 pour premier affichage
|
||||
int x=XMAX/2, y=YMAX/2;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
lis.begin(Wire1);
|
||||
|
||||
if (!lis) {
|
||||
Serial.println("ERROR");
|
||||
while(1);
|
||||
}
|
||||
lis.setOutputDataRate(LIS3DHTR_DATARATE_25HZ); //Data output rate
|
||||
lis.setFullScaleRange(LIS3DHTR_RANGE_2G); //Scale range set to 2g
|
||||
|
||||
tft.begin();
|
||||
tft.fillScreen(TFT_WHITE); // fond blanc
|
||||
|
||||
pinMode(WIO_KEY_A, INPUT_PULLUP);
|
||||
pinMode(WIO_KEY_B, INPUT_PULLUP);
|
||||
pinMode(WIO_KEY_C, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
float x_a,y_a;
|
||||
x_a = lis.getAccelerationX() * 100-4;
|
||||
y_a = lis.getAccelerationY() * 100+1;
|
||||
|
||||
Serial.print(" X: "); Serial.print(x_a); Serial.print(" x: "); Serial.print(x);
|
||||
Serial.print(" Y: "); Serial.print(y_a); Serial.print(" y: "); Serial.print(y);
|
||||
Serial.println();
|
||||
|
||||
|
||||
//tft.fillCircle(x,y,R + 1,TFT_WHITE);
|
||||
//on affiche le nouveau cercle
|
||||
//tft.fillCircle(x_a,y_a, R, TFT_RED);
|
||||
|
||||
if (x_a > 0 ) { // penche vers nous
|
||||
modif=1;
|
||||
Serial.print("mouvement vers nous");
|
||||
Serial.println();
|
||||
x++;
|
||||
if (x >= XMAX) {
|
||||
Serial.print("MUR TOUCHÉ VERS NOUS TOUCHÉ!");
|
||||
// perdu();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (x_a < 0 ) { // penche vers l'arrière
|
||||
modif=1;
|
||||
Serial.print("mouvement vers l'arrière");
|
||||
Serial.println();
|
||||
x--;
|
||||
if (x <= 0) {
|
||||
Serial.print("MUR TOUCHÉ A L'ARRIÈRE TOUCHÉ!");
|
||||
// perdu();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (y_a < 0 ) { // penche vers l'arrière
|
||||
modif=1;
|
||||
Serial.print("mouvement vers la droite");
|
||||
Serial.println();
|
||||
y--;
|
||||
if (y <= 0) {
|
||||
Serial.print("MUR TOUCHÉ VERS LA DROITE TOUCHÉ!");
|
||||
// perdu();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (y_a > 0 ) { // penche vers l'arrière
|
||||
modif=1;
|
||||
Serial.print("mouvement vers la gauche");
|
||||
Serial.println();
|
||||
y++;
|
||||
if (y >= YMAX) {
|
||||
Serial.print("MUR TOUCHÉ VERS LA GAUCHE TOUCHÉ!");
|
||||
// perdu();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (modif == 1){
|
||||
// on affiche le nouveau cercle
|
||||
tft.fillCircle(x,y,R + 2,TFT_WHITE);
|
||||
tft.fillCircle(x,y, R, TFT_RED);
|
||||
modif=0;
|
||||
}
|
||||
delay(50);
|
||||
|
||||
// put your main code here, to run repeatedly:
|
||||
if (digitalRead(WIO_KEY_C) == LOW) {
|
||||
Serial.println("C Key pressed");
|
||||
}
|
||||
else if (digitalRead(WIO_KEY_B) == LOW) {
|
||||
Serial.println("B Key pressed");
|
||||
}
|
||||
else if (digitalRead(WIO_KEY_A) == LOW) {
|
||||
Serial.println("A Key pressed");
|
||||
}
|
||||
}
|
||||
|
||||
//void perdu() {
|
||||
// tft.fillScreen(TFT_RED); // fond blanc
|
||||
//}
|
||||
|
||||
|
||||
// déplacement vers l'arrière : x diminue
|
||||
// déplacement vers nous : x augmente
|
||||
// déplacement vers la gauche : y augmente
|
||||
// déplacement vers la droite : y diminue
|
||||
// Exemple de résultat : X: 0.08 Y: -0.09 Z: -1.02
|
||||
// En pourcentage donc convertir.
|
||||
|
||||
// x_a = lis.getAccelerationX() * 100-4; // Correspond au y de l'écran
|
||||
// y_a = lis.getAccelerationY() * 100+1; // Correspond au -x de l'écran
|
Loading…
Reference in new issue