Compass - dtex/johnny-five GitHub Wiki
The Compass class constructs an object that represents a single Compass or Magnetometer.
Supported Compass/Magnetometer:
- HMC6352
- No longer in production, but we assume people may still have them.
- HMC5883L
This list will continue to be updated as more component support is implemented.
-
Options An object of property parameters.
Property Type Value/Description Default Required controller String HMC6352, HMC5883L. The name of the controller to use yes gauss Number cgs units. Set the scale gauss for compass readings. 1.3 no
| Property Name | Description | Read Only |
|---|---|---|
heading |
The current heading in degrees, 0-360° | Yes |
bearing |
An object of properties whose values are relevant bearing information ★ | Yes |
-
bearing ★
Property Name Description Read Only pointA cardinal direction, eg. "north", "south", "east", "west" No abbrAbbreviated point, eg. "N", "NE", "NEbE"No lowLow end of cardinal range in degrees No midMiddle end of cardinal range in degrees No highHigh end of cardinal range in degrees No
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.
