-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Compass
Rick Waldron edited this page Feb 2, 2015
·
34 revisions
The Compass
class constructs an object that represents a single Compass or Magnetometer.
Supported Compass/Magnetometer:
- HMC6352
- HMC5883L
- options An object of property parameters.
Property Name | Type | Value(s) | Description | Required |
---|---|---|---|---|
controller | String | HMC6352, HMC5883L | Defines the compass module device | yes |
gauss | Number | cgs units | Set the scale gauss for compass readings. Defaults to 1.3 | no |
{
heading: The current heading in degrees, 0-360°
bearing: {
// Example
point: "North",
abbr: "N",
low: 354.38,
mid: 360,
high: 360
}
}
var compass = new five.Compass({
controller: "HMC6352"
});
var compass = new five.Compass({
controller: "HMC5883L"
});
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var compass = new five.Compass({
controller: "HMC6352"
});
compass.on("headingchange", function() {
console.log("headingchange");
console.log(" heading : ", Math.floor(this.heading));
console.log(" bearing : ", this.bearing.name);
console.log("--------------------------------------");
});
compass.on("data", function() {
console.log(" heading : ", Math.floor(this.heading));
console.log(" bearing : ", this.bearing.name);
console.log("--------------------------------------");
});
});
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var compass = new five.Compass({
controller: "HMC5883L"
});
compass.on("headingchange", function() {
console.log("headingchange");
console.log(" heading : ", Math.floor(this.heading));
console.log(" bearing : ", this.bearing.name);
console.log("--------------------------------------");
});
compass.on("data", function() {
console.log(" heading : ", Math.floor(this.heading));
console.log(" bearing : ", this.bearing.name);
console.log("--------------------------------------");
});
});
- change The "change" event is emitted whenever the heading of the compass has changed from it's last position
- data The "data" event is fired as frequently as the user defined freq will allow in milliseconds.