@@ -29,24 +29,12 @@ node eg/accelerometer.js
29
29
30
30
31
31
``` javascript
32
- var five = require (" johnny-five" ),
33
- board, accel ;
32
+ const { Accelerometer , Board } = require (" johnny-five" );
33
+ const board = new Board () ;
34
34
35
- board = new five.Board ();
35
+ board . on ( " ready " , () => {
36
36
37
- board .on (" ready" , function () {
38
-
39
- // Create a new analog `Accelerometer` hardware instance.
40
- //
41
- // five.Accelerometer([ x, y[, z] ]);
42
- //
43
- // five.Accelerometer({
44
- // pins: [ x, y[, z] ]
45
- // freq: ms
46
- // });
47
- //
48
-
49
- accel = new five.Accelerometer ({
37
+ const accelerometer = new Accelerometer ({
50
38
pins: [" A3" , " A4" , " A5" ],
51
39
52
40
// Adjust the following for your device.
@@ -56,56 +44,17 @@ board.on("ready", function() {
56
44
zeroV: 478 // volts in ADC
57
45
});
58
46
59
- // Accelerometer Event API
60
-
61
-
62
- // "data"
63
- //
64
- // Fires when X, Y or Z has changed.
65
- //
66
- // The first argument is an object containing raw x, y, z
67
- // values as read from the analog input.
68
- //
69
- accel .on (" data" , function (data ) {
70
-
71
- console .log (" raw: " , data);
72
- });
73
-
74
- // "acceleration"
75
- //
76
- // Fires once every N ms, equal to value of freg
77
- // Defaults to 500ms
78
- //
79
- accel .on (" acceleration" , function (data ) {
80
-
81
- console .log (" acceleration" , data);
82
- });
83
-
84
- // "orientation"
85
- //
86
- // Fires when orientation changes
87
- //
88
- accel .on (" orientation" , function (data ) {
89
-
90
- console .log (" orientation" , data);
91
- });
92
-
93
- // "inclination"
94
- //
95
- // Fires when inclination changes
96
- //
97
- accel .on (" inclination" , function (data ) {
98
-
99
- console .log (" inclination" , data);
100
- });
101
-
102
- // "change"
103
- //
104
- // Fires when X, Y or Z has changed
105
- //
106
- accel .on (" change" , function (data ) {
107
-
108
- console .log (" change" , data);
47
+ accelerometer .on (" change" , () => {
48
+ console .log (" accelerometer" );
49
+ console .log (" x : " , accelerometer .x );
50
+ console .log (" y : " , accelerometer .y );
51
+ console .log (" z : " , accelerometer .z );
52
+ console .log (" pitch : " , accelerometer .pitch );
53
+ console .log (" roll : " , accelerometer .roll );
54
+ console .log (" acceleration : " , accelerometer .acceleration );
55
+ console .log (" inclination : " , accelerometer .inclination );
56
+ console .log (" orientation : " , accelerometer .orientation );
57
+ console .log (" --------------------------------------" );
109
58
});
110
59
});
111
60
0 commit comments