|
#include <WiFiNINA.h>
#include <Arduino_LSM6DSOX.h>
float Ax, Ay, Az;
float Gx, Gy, Gz;
void setup() {
Serial.begin(9600);
while (!Serial);
// IMU
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println("Hz");
Serial.println();
Serial.print("Gyroscope sample rate = ");
Serial.print(IMU.gyroscopeSampleRate());
Serial.println("Hz");
Serial.println();
}
void imuHandle() {
bool needUpdate = 0;
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(Ax, Ay, Az);
needUpdate = 1;
}
if (IMU.gyroscopeAvailable()) {
IMU.readGyroscope(Gx, Gy, Gz);
needUpdate = 1;
}
if(needUpdate) {
Serial.print("Ax: ");
Serial.print(Ax);
Serial.print(", Ay: ");
Serial.print(Ay);
Serial.print(", Az: ");
Serial.print(Az);
Serial.print(", Gx: ");
Serial.print(Gx);
Serial.print(", Gy: ");
Serial.print(Gy);
Serial.print(", Gz: ");
Serial.print(Gz);
Serial.println();
}
}
void loop() {
imuHandle();
}
总结