-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Compass
Rick Waldron edited this page Nov 13, 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 Type Value/Description Default Required controller String "HMC6352", "HMC5883L". Defines the compass module device yes gauss Number cgs units. Set the scale gauss for compass readings. 1.3 no
{
heading: The current heading in degrees, 0-360°
bearing: {
// Example
point: "North",
abbr: "N",
low: 354.38,
mid: 360,
high: 360
}
}
Property Name | Description | Read Only |
---|---|---|
heading |
The current heading in degrees, 0-360° | Yes |
bearing |
An object containing properties whose values are relevant bearing information (See below) | Yes |
Property Name | Description | Read Only |
---|---|---|
point |
A cardinal direction, eg. "north", "south", "east", "west" | Yes |
abbr |
Abbreviated point , eg. "N", "NE", "NEbE" |
Yes |
low |
Low end of cardinal range in degrees | Yes |
mid |
Middle end of cardinal range in degrees | Yes |
high |
High end of cardinal range in degrees | Yes |
new five.Compass({
controller: "HMC6352"
});
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("--------------------------------------");
});
});
There are no special API functions for this class.
- 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.