Arduino micro ne detecte pas mon mpu 6050

bonjour j'ai pour projet de faire une manette de jeu pour pc avec un arduino micro qui emulera mon clavier et ma souri

j'ai mis un bouton poussoir derrière la gâchette et une autre derrière la culasse d'un pistolet a bille et un gyroscope mpu 6050 sou le canon pour émuler la souri

le problème c'est que les bouton fonctionne bien mais les touche ne sont que très rarement appuyé et que le gyroscope n'est pas lu avec l'arduino micro
voici mon code

/*
          cablage
-------------------------------------------------- 
digital:

2 = recharge

3 = gachet

5 = 5V

6 = 5V

7 = GND
*/

#include <Wire.h>

#include <Mouse.h>

#include <Keyboard.h>

int etatrechar = 0;

int etatgachet = 0;
int avantx = 0;
int apresx = 0;

int avantz = 0;
int apresz = 0;

int totalx = 0;
int totalz = 0;

const int MPU_addr = 0x68; int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;

int minVal = 265; int maxVal = 402;

double x; double y; double z;

void setup() {
  pinMode(8,INPUT);
  pinMode(9,INPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,INPUT);
  
  digitalWrite(5,OUTPUT);
  digitalWrite(6,OUTPUT);
  
  Keyboard.begin();
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  Serial.begin(9600);
  Mouse.begin();
  
}
void loop() {
  calculgyroscope();
  delay(100);
  avantx = digitalRead(GyX);
  avantz = digitalRead(GyZ);
  delay(100);
  apresx = digitalRead(GyX);
  apresz = digitalRead(GyZ);
  delay(100);
  totalx = apresx - avantx;
  totalz = apresz - avantz;
  delay(100);
  Mouse.move(GyX, GyZ, 0);

 etatrechar = digitalRead(2);

  if (etatrechar == HIGH){
  }else{
    Keyboard.print("r");
    Serial.println("r");
  }
  
  etatgachet = digitalRead(3);

  if (etatgachet == HIGH){
    
  }else{
    Keyboard.print("e");
    Serial.println("e");
  }
}











void calculgyroscope (){
Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr, 14, true);
  AcX = Wire.read() << 8 | Wire.read();
  AcY = Wire.read() << 8 | Wire.read();
  AcZ = Wire.read() << 8 | Wire.read();
  int xAng = map(AcX, minVal, maxVal, -90, 90);
  int yAng = map(AcY, minVal, maxVal, -90, 90);
  int zAng = map(AcZ, minVal, maxVal, -90, 90);

  x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
  y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI);
  z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);

  Serial.print("AngleX= "); Serial.println(x);

  Serial.print("AngleY= "); Serial.println(y);

  Serial.print("AngleZ= "); Serial.println(z); Serial.println("-----------------------------------------");Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr, 14, true);
  AcX = Wire.read() << 8 | Wire.read();
  AcY = Wire.read() << 8 | Wire.read();
  AcZ = Wire.read() << 8 | Wire.read();
   xAng = map(AcX, minVal, maxVal, -90, 90);// si il y a un problem le code a la base avais "int" devans "xAng
   yAng = map(AcY, minVal, maxVal, -90, 90);// si il y a un problem le code a la base avais "int" devans "yAng
   zAng = map(AcZ, minVal, maxVal, -90, 90);// si il y a un problem le code a la base avais "int" devans "zAng

 

  Serial.print("AngleX= "); Serial.println(x);

  Serial.print("AngleY= "); Serial.println(y);

  Serial.print("AngleZ= "); Serial.println(z); Serial.println("-----------------------------------------");
}







  

merci de votre réponce

Tienes todo mezclado en tu código.
la función digitalRead() no se puede utilizar para leer datos del acelerómetro

Update:
Sorry, yesterday first post was in spanish or i thought?

:warning:

Post mis dans la mauvaise section, on parle anglais dans les forums généraux. ➜ déplacé vers le forum francophone.

Merci de prendre en compte les recommandations listées dans “Les bonnes pratiques du Forum Francophone”

GyX, GyZ ne contiennent aucune valeur il n'y a jamais aucune affection de ces variables

Le code a mon avis fonction car il marche sur une uno sauf que je l'écris dans le Moniteur série.si il y a gx et gz c'est par ce que je pensais pourvoir encore plus l'améliorer plus tard

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.