mpu update

This commit is contained in:
Luthics 2022-12-17 20:46:19 +08:00
parent e4ae7bce0e
commit ad36a04f40
2 changed files with 46 additions and 0 deletions

View File

@ -18,4 +18,5 @@ lib_deps =
ottowinter/ESPAsyncWebServer-esphome@^3.0.0 ottowinter/ESPAsyncWebServer-esphome@^3.0.0
teckel12/NewPing@^1.9.5 teckel12/NewPing@^1.9.5
gitlab-airbornemint/Protothreads@^1.4.0-arduino.beta.1 gitlab-airbornemint/Protothreads@^1.4.0-arduino.beta.1
adafruit/Adafruit MPU6050@^2.2.4
monitor_speed = 115200 monitor_speed = 115200

View File

@ -0,0 +1,45 @@
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <mpu.h>
Adafruit_MPU6050 mpu;
void mpu_init() {
if (!mpu.begin()) {
while (1) {
delay(10);
}
}
mpu.setHighPassFilter(MPU6050_HIGHPASS_0_63_HZ);
mpu.setMotionDetectionThreshold(1);
mpu.setMotionDetectionDuration(20);
mpu.setInterruptPinLatch(true);
mpu.setInterruptPinPolarity(true);
mpu.setMotionInterrupt(true);
}
void mpu_loop() {
if (mpu.getMotionInterruptStatus()) {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
Serial.print("AccelX:");
Serial.print(a.acceleration.x);
Serial.print(",");
Serial.print("AccelY:");
Serial.print(a.acceleration.y);
Serial.print(",");
Serial.print("AccelZ:");
Serial.print(a.acceleration.z);
Serial.print(", ");
Serial.print("GyroX:");
Serial.print(g.gyro.x);
Serial.print(",");
Serial.print("GyroY:");
Serial.print(g.gyro.y);
Serial.print(",");
Serial.print("GyroZ:");
Serial.print(g.gyro.z);
Serial.println("");
}
}