mpu update
This commit is contained in:
parent
e4ae7bce0e
commit
ad36a04f40
|
@ -18,4 +18,5 @@ lib_deps =
|
|||
ottowinter/ESPAsyncWebServer-esphome@^3.0.0
|
||||
teckel12/NewPing@^1.9.5
|
||||
gitlab-airbornemint/Protothreads@^1.4.0-arduino.beta.1
|
||||
adafruit/Adafruit MPU6050@^2.2.4
|
||||
monitor_speed = 115200
|
||||
|
|
45
src/mpu.cpp
45
src/mpu.cpp
|
@ -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("");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue