|
1 |
| -var five = require("../lib/johnny-five.js"); |
2 |
| -var board = new five.Board(); |
| 1 | +const {Accelerometer, Board} = require("../lib/johnny-five.js"); |
| 2 | +const board = new Board(); |
3 | 3 |
|
4 |
| -board.on("ready", function() { |
5 |
| - var accelerometer = new five.Accelerometer({ |
| 4 | +board.on("ready", () => { |
| 5 | + const accelerometer = new Accelerometer({ |
6 | 6 | controller: "LIS3DH",
|
7 | 7 | // Optionally set the range to one of
|
8 | 8 | // 2, 4, 8, 16 (±g)
|
9 | 9 | // Defaults to ±2g
|
10 | 10 | // range: ...
|
11 | 11 | });
|
12 | 12 |
|
13 |
| - accelerometer.on("change", function() { |
14 |
| - console.log("accelerometer"); |
15 |
| - console.log(" x : ", this.x); |
16 |
| - console.log(" y : ", this.y); |
17 |
| - console.log(" z : ", this.z); |
18 |
| - // console.log(" pitch : ", this.pitch); |
19 |
| - // console.log(" roll : ", this.roll); |
20 |
| - // console.log(" acceleration : ", this.acceleration); |
21 |
| - // console.log(" inclination : ", this.inclination); |
22 |
| - // console.log(" orientation : ", this.orientation); |
| 13 | + accelerometer.on("change", () => { |
| 14 | + const {acceleration, inclination, orientation, pitch, roll, x, y, z} = accelerometer; |
| 15 | + console.log("Accelerometer:"); |
| 16 | + console.log(" x : ", x); |
| 17 | + console.log(" y : ", y); |
| 18 | + console.log(" z : ", z); |
| 19 | + console.log(" pitch : ", pitch); |
| 20 | + console.log(" roll : ", roll); |
| 21 | + console.log(" acceleration : ", acceleration); |
| 22 | + console.log(" inclination : ", inclination); |
| 23 | + console.log(" orientation : ", orientation); |
23 | 24 | console.log("--------------------------------------");
|
24 | 25 | });
|
25 | 26 |
|
26 |
| - ["tap", "tap:single", "tap:double"].forEach(function(event) { |
27 |
| - accelerometer.on(event, function() { |
| 27 | + ["tap", "tap:single", "tap:double"].forEach((event) => { |
| 28 | + accelerometer.on(event, () => { |
28 | 29 | console.log(event);
|
29 | 30 | });
|
30 | 31 | });
|
|
0 commit comments