-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
49 lines (37 loc) · 986 Bytes
/
example.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
44
45
46
47
48
49
'use strict';
var heading0;
var heading1;
var Compass = require('compass-hmc5883l');
var compass = new Compass(1);
var Compass0 = require('compass-hmc5883l');
var compass0 = new Compass(0);
// Gets called every time we get the values.
function printHeadingCB(err, heading) {
if (err) {
console.log(err);
return;
}
heading1 = heading.toFixed(0);
}
function printHeadingCB0(err, heading) {
if (err) {
console.log(err);
return;
}
heading0 = heading.toFixed(0);
}
// Get the compass values every 100 milliseconds
setInterval(function() {
compass.getHeadingDegrees('x', 'y', printHeadingCB);
compass0.getHeadingDegrees('x', 'y', printHeadingCB0);
console.log(`heading0: ${heading0} heading1: ${heading1}`);
}, 100);
//
// var Compass = require('compass-hmc5883l');
// var compass = new Compass(2);
//
// // Get the compass values
// compass.getHeading('x', 'y', function (err, heading) {
// console.log(heading * 180 / Math.PI);
// });
//