Skip to content

Instantly share code, notes, and snippets.

@hollyhockberry
Last active August 10, 2022 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hollyhockberry/ed3172324f2d1bda842bf6fa7286c599 to your computer and use it in GitHub Desktop.
Save hollyhockberry/ed3172324f2d1bda842bf6fa7286c599 to your computer and use it in GitHub Desktop.
Sample: plot accel data
#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