Created
July 22, 2015 21:41
-
-
Save fivdi/df237d9624cd87042702 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var five = require("johnny-five"); | |
var BeagleBone = require("beaglebone-io"); | |
var board = new five.Board({ | |
io: new BeagleBone() | |
}); | |
board.on("ready", function() { | |
var accelerometer = new five.Accelerometer({ | |
controller: "ADXL345" | |
}); | |
var compass = new five.Compass({ | |
controller: "HMC5883L" | |
}); | |
var x, y, z; | |
var heading, bearing; | |
var accelerometerReadings = 0; | |
var compassReadings = 0; | |
setInterval(function () { | |
console.log(compassReadings + ' ' | |
+ heading + ' ' | |
+ bearing + ' ' | |
+ accelerometerReadings + ' ' | |
+ x + ' ' | |
+ y + ' ' | |
+ x + ' ' | |
); | |
}, 500); | |
accelerometer.on("data", function() { | |
x = this.x; | |
y = this.y; | |
z = this.z; | |
accelerometerReadings += 1; | |
}); | |
compass.on("data", function() { | |
heading = Math.floor(this.heading); | |
bearing = this.bearing.name; | |
compassReadings += 1; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment