Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 115 lines (73 sloc) 1.835 kB
6b5ab5b @rwaldron Rebuild all example program markdown files
authored
1 # Magnetometer
2
3 Run with:
4 ```bash
5 node eg/magnetometer.js
6 ```
7
8
9 ```javascript
10 var five = require("johnny-five"),
11 mag;
12
13 five.Board().on("ready", function() {
14
15 // Create a new `Magnetometer` hardware instance.
16 //
17 // five.Magnetometer();
18 //
19 // (Alias of:
20 // new five.Compass({
21 // device: "HMC5883L",
22 // freq: 50,
23 // gauss: 1.3
24 // });
25 // )
26 //
27
28 mag = new five.Magnetometer();
29
30
31 // Properties
32
33 // mag.raw
34 //
35 // x, y, z
36 //
37
38 // mag.scaled
39 //
40 // axis x, y, z
41 //
42 // based on value stored at (mag.scale)
43 //
44
45 // mag.heading
46 //
47 // Calculated heading in degrees (calibrated for magnetic north)
48 //
49
50 // mag.bearing
51 //
52 // Bearing data object
53 //
54
55
56 // Magnetometer Event API
57
58 // "headingchange"
59 //
60 // Fires when the calculated heading has changed
61 //
62 mag.on("headingchange", function() {
63
64 console.log( "heading", Math.floor(this.heading) );
65 console.log( "bearing", this.bearing );
66
67 });
68
69 // "read"
70 //
71 // Fires continuously, every 66ms.
72 //
73 mag.on("read", function( err, timestamp ) {
74 // console.log( "read", this.axis );
75 });
76 });
77
78 ```
79
80 ## Breadboard
81
82 <img src="https://raw.github.com/rwldrn/johnny-five/master/docs/breadboard/magnetometer.png">
83
84 [magnetometer.fzz](https://github.com/rwldrn/johnny-five/blob/master/docs/breadboard/magnetometer.fzz)
85
86
5e929ce @rwaldron Example program updates
authored
87
88 ## Devices
89
90
91
92
6b5ab5b @rwaldron Rebuild all example program markdown files
authored
93 ## Documentation
94
95 _(Nothing yet)_
96
97
98
99
100
101
102
103
104
105 ## Contributing
106 All contributions must adhere to the the [Idiomatic.js Style Guide](https://github.com/rwldrn/idiomatic.js),
107 by maintaining the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/cowboy/grunt).
108
109 ## Release History
110 _(Nothing yet)_
111
112 ## License
113 Copyright (c) 2012 Rick Waldron <waldron.rick@gmail.com>
114 Licensed under the MIT license.
Something went wrong with that request. Please try again.