
 

#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
void MpuInt(){
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
  //setupt motion detection
  mpu.setHighPassFilter(MPU6050_HIGHPASS_0_63_HZ);
  mpu.setMotionDetectionThreshold(1);
  mpu.setMotionDetectionDuration(20);
  mpu.setInterruptPinLatch(true);  // Keep it latched.  Will turn off when reinitialized.
  mpu.setInterruptPinPolarity(true);
  mpu.setMotionInterrupt(true);
  }
void MpuGet(){
   if(mpu.getMotionInterruptStatus()) {
    sensors_event_t a, g, temp;
    mpu.getEvent(&a, &g, &temp);
    
    String msg=String()+
               +"AccelX:"+String(a.acceleration.x)
               +" AccelY:"+String(a.acceleration.x)
               +" AccelZ:"+String(a.acceleration.x)
               +" GyroX:"+String(g.gyro.x)
               +" GyroY:"+String(g.gyro.x)
               +" GyroZ:"+String(g.gyro.x)
               ;     
    Serial.println(msg);                  
  }
}
  
void setup(void) {
  Serial.begin(9600);
  while (!Serial)
    delay(10); 
  Serial.println("Adafruit MPU6050 test!");
  MpuInt();
  Serial.println("MPU6050 Found!");
  delay(100);
}
void loop() {
  MpuGet();
  delay(10);
}
 
                    
                     
                    
                 
                    
                 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号