Last active
August 10, 2022 07:54
-
-
Save hollyhockberry/ed3172324f2d1bda842bf6fa7286c599 to your computer and use it in GitHub Desktop.
Sample: plot accel data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <M5StickC.h> | |
float _x, _y, _z; | |
void setup() { | |
M5.begin(); | |
M5.Imu.Init(); | |
M5.IMU.getAccelData(&_x, &_y, &_z); | |
} | |
static bool flag(float d) { | |
const auto thres = 0.04f; | |
return d > thres; | |
} | |
static int flag(float dx, float dy, float dz) { | |
return (flag(dx) || flag(dy) || flag(dz)) ? 5 : 0; | |
} | |
void loop() { | |
float x, y, z; | |
M5.IMU.getAccelData(&x, &y, &z); | |
float dx = ::abs(x - _x); | |
float dy = ::abs(y - _y); | |
float dz = ::abs(z - _z); | |
Serial.printf("dx,dy,dz,flag\r\n"); | |
Serial.printf("%5.2f,%5.2f,%5.2f,%d\r\n", dx, dy, dz, flag(dx, dy, dz)); | |
_x = x; | |
_y = y; | |
_z = z; | |
::delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment