forked from kevinwlu/iot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XIAO-gestures.ino
43 lines (34 loc) · 1.22 KB
/
XIAO-gestures.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "LSM6DS3.h"
#include "Wire.h"
//Create a instance of class LSM6DS3
LSM6DS3 myIMU(I2C_MODE, 0x6A); //I2C device address 0x6A
#define CONVERT_G_TO_MS2 9.80665f
#define FREQUENCY_HZ 50
#define INTERVAL_MS (1000 / (FREQUENCY_HZ + 1))
static unsigned long last_interval_ms = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial);
//Call .begin() to configure the IMUs
if (myIMU.begin() != 0) {
Serial.println("Device error");
} else {
Serial.println("Device OK!");
}
}
void loop() {
if (millis() > last_interval_ms + INTERVAL_MS) {
last_interval_ms = millis();
Serial.print(myIMU.readFloatAccelX() * CONVERT_G_TO_MS2,4);
Serial.print('\t');
Serial.print(myIMU.readFloatAccelY() * CONVERT_G_TO_MS2,4);
Serial.print('\t');
Serial.println(myIMU.readFloatAccelZ() * CONVERT_G_TO_MS2,4);
//Serial.print(myIMU.readFloatGyroX() * CONVERT_G_TO_MS2,4);
//Serial.print('\t');
//Serial.print(myIMU.readFloatGyroY() * CONVERT_G_TO_MS2,4);
//Serial.print('\t');
//Serial.println(myIMU.readFloatGyroZ() * CONVERT_G_TO_MS2,4);
}
}