From 41d4b12391630a1787941285040db60e07f6ba11 Mon Sep 17 00:00:00 2001 From: "arsene.poulain" Date: Tue, 13 May 2025 10:12:52 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20accelerom=C3=A8tre=20+=20fonctions=20bo?= =?UTF-8?q?uttons=20A,B=20et=20C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sketch_mar26a/sketch_mar26a.ino | 1 + sketch_mar26a/tests_wio.ino | 65 ++++++++++++++++ sketch_mar26a/wino.ino | 126 ++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 sketch_mar26a/sketch_mar26a.ino create mode 100644 sketch_mar26a/tests_wio.ino create mode 100644 sketch_mar26a/wino.ino diff --git a/sketch_mar26a/sketch_mar26a.ino b/sketch_mar26a/sketch_mar26a.ino new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/sketch_mar26a/sketch_mar26a.ino @@ -0,0 +1 @@ + diff --git a/sketch_mar26a/tests_wio.ino b/sketch_mar26a/tests_wio.ino new file mode 100644 index 0000000..e1e1989 --- /dev/null +++ b/sketch_mar26a/tests_wio.ino @@ -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); +//} diff --git a/sketch_mar26a/wino.ino b/sketch_mar26a/wino.ino new file mode 100644 index 0000000..4aa8519 --- /dev/null +++ b/sketch_mar26a/wino.ino @@ -0,0 +1,126 @@ +#include"LIS3DHTR.h" +#include "TFT_eSPI.h" +LIS3DHTR 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