Created
May 14, 2021 12:29
-
-
Save ksasao/7b90a1392dd580768502bf096d5d39bf to your computer and use it in GitHub Desktop.
M5StickCで重力の向きを計測。単位はG。シリアル出力は115200bps/パリティなし/8データビット/1ストップビット(デフォルト値)。
This file contains hidden or 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 accX = 0; | |
| float accY = 0; | |
| float accZ = 0; | |
| void setup() { | |
| M5.begin(); | |
| M5.IMU.Init(); | |
| M5.Lcd.setRotation(3); | |
| M5.Lcd.fillScreen(BLACK); | |
| M5.Lcd.setTextSize(2); | |
| } | |
| void loop() { | |
| float x = 0; | |
| float y = 0; | |
| float z = 0; | |
| int count = 100; | |
| for(int i=0; i<count; i++){ | |
| M5.IMU.getAccelData(&accX,&accY,&accZ); | |
| x += accX; | |
| y += accY; | |
| z += accZ; | |
| delay(1); | |
| } | |
| x /= count; | |
| y /= count; | |
| z /= count; | |
| M5.Lcd.setCursor(0, 20); | |
| M5.Lcd.printf("X: %+6.3f \n",x); | |
| M5.Lcd.printf("Y: %+6.3f \n",y); | |
| M5.Lcd.printf("Z: %+6.3f \n",z); | |
| Serial.printf("%.3f,%.3f,%.3f",x,y,z); | |
| Serial.println(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment