Skip to content

Instantly share code, notes, and snippets.

@TakehikoShimojima
Last active March 13, 2020 07:53
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 TakehikoShimojima/d136e81e13eeea603a8e594a8f5ef90f to your computer and use it in GitHub Desktop.
Save TakehikoShimojima/d136e81e13eeea603a8e594a8f5ef90f to your computer and use it in GitHub Desktop.
#include <M5StickC.h>
#define SAMPLE_PERIOD 20 // サンプリング間隔(ミリ秒)
#define SAMPLE_SIZE 150 // 20ms x 150 = 3秒
void setup() {
M5.begin();
M5.Lcd.setRotation(3);
M5.MPU6886.Init(); // MPU6886を初期設定する
}
float ax, ay, az[SAMPLE_SIZE]; // 加速度データを読み出す変数
#define X0 5 // 横軸の描画開始座標
#define MINZ 600 // 縦軸の最小値 600mG
#define MAXZ 1400 // 縦軸の最大値 1400mG
void loop() {
M5.Lcd.fillScreen(BLACK); // 画面をクリア
for (int i = 0; i < SAMPLE_SIZE; i++) {
M5.MPU6886.getAccelData(&ax,&ay,&az[i]); // MPU6886から加速度を取得
az[i] *= 1000; // mGに変換
if (i == 0) continue;
int y0 = map((int)(az[i - 1]), MINZ, MAXZ, M5.Lcd.height(), 0);
int y1 = map((int)(az[i]), MINZ, MAXZ, M5.Lcd.height(), 0);
M5.Lcd.drawLine(i - 1 + X0, y0, i + X0, y1, GREEN);
delay(SAMPLE_PERIOD);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment