-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtpt.ino
58 lines (46 loc) · 884 Bytes
/
tpt.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
44
45
46
47
48
49
50
51
52
53
54
55
56
// Two-point Pinch Test (TPT)
#include <Wire.h>
#include "MMA7660.h"
MMA7660 accelemeter;
void setup()
{
accelemeter.init();
Serial.begin(19200);
}
void loop()
{
// position
int8_t x, y, z;
// acceleration
float ax, ay, az;
float g = 9.8066;
// timing
unsigned long t1, t2, t, d;
// sampling frequency: 50 Hz
int fs = 50;
// microseconds
t1 = micros();
accelemeter.getXYZ(&x, &y, &z);
accelemeter.getAcceleration(&ax, &ay, &az);
// convert from g to m/s2
ax *= g;
ay *= g;
az *= g;
Serial.print("tpt: ");
Serial.print(x);
Serial.print(" ");
Serial.print(y);
Serial.print(" ");
Serial.print(z);
Serial.print(" ");
Serial.print(ax, 3);
Serial.print(" ");
Serial.print(ay, 3);
Serial.print(" ");
Serial.println(az, 3);
// microseconds
t2 = micros();
t = (t2 - t1) / 1000.0;
d = (1000.0 / fs) - t;
delay(d);
}