Created
August 30, 2020 05:44
-
-
Save botamochi6277/41c77ef9da1a20d238cfa5ea0c5cf9d6 to your computer and use it in GitHub Desktop.
Tilt Sensor Example for M5Atom Matrix
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
/** | |
* @file M5AtomTilt.ino | |
* @author botamochi6277 | |
* @brief tilt sensor application fot M5Atom Matrix | |
* acc value is unstable. I recommend to add filters. | |
* @version 0.1 | |
* @date 2020-08-30 | |
* | |
* @licence MIT LICENCE | |
* | |
*/ | |
#include "M5Atom.h" | |
bool IMU6886Flag = false; | |
float accX = 0, accY = 0, accZ = 0; | |
int range = 500; | |
void setup() | |
{ | |
M5.begin(true, false, true); | |
if (M5.IMU.Init() != 0) | |
{ | |
IMU6886Flag = false; | |
} | |
else | |
{ | |
IMU6886Flag = true; | |
} | |
} | |
void loop() | |
{ | |
if (IMU6886Flag == true) | |
{ | |
M5.IMU.getAccelData(&accX, &accY, &accZ); | |
// convert acc value to matrix position with arduino map func. | |
int x = map(int(accX * 1000), -range, range, 0, 4); | |
x = constrain(x, 0, 4); // limit value | |
int y = map(int(accY * 1000), -range, range, 0, 4); | |
y = constrain(y, 0, 4); | |
// display | |
M5.dis.clear(); | |
M5.dis.drawpix(x, y, CRGB::White); | |
delay(500); | |
M5.update(); | |
Serial.printf("%.2f,%.2f,%.2f mg\r\n", accX * 1000, accY * 1000, accZ * 1000); | |
} | |
else | |
{ | |
// Fail to initialize IMU (Maybe) | |
M5.dis.clear(); | |
M5.dis.drawpix(2, 2, CRGB::Red); | |
delay(500); | |
M5.update(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment