-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
43 lines (39 loc) · 974 Bytes
/
test.js
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
global.XAXIS = 0;
global.YAXIS = 1;
global.ZAXIS = 2;
var ADXL345 = require('./index.js');
var globalvar = {
SAMPLECOUNT : 400,
accelScaleFactor : [0.0, 0.0, 0.0],
runTimeAccelBias : [0, 0, 0],
accelOneG : 0.0,
meterPerSecSec : [0.0, 0.0, 0.0],
accelSample : [0, 0, 0],
accelSampleCount : 0
}
var accel = new ADXL345(function(err) {
accel.accelScaleFactor[XAXIS] = 0.0371299982;
accel.accelScaleFactor[YAXIS] = -0.0374319982;
accel.accelScaleFactor[ZAXIS] = -0.0385979986;
if (!err) {
computeAccelBias();
} else {
console.log(err);
}
})
function computeAccelBias() {
accel.computeAccelBias(function() {
measureAccel();
});
}
function measureAccel() {
setInterval(function() {
accel.measureAccel(function(err) {
if (!err) {
console.log("Roll: " + accel.meterPerSecSec[global.XAXIS] + " Pitch : " + accel.meterPerSecSec[global.YAXIS] + " Yaw : " + accel.meterPerSecSec[global.ZAXIS]);
} else {
console.log(err);
}
});
}, 10);
}