Skip to content

Instantly share code, notes, and snippets.

@fivdi
Created July 22, 2015 21:41
Show Gist options
  • Save fivdi/df237d9624cd87042702 to your computer and use it in GitHub Desktop.
Save fivdi/df237d9624cd87042702 to your computer and use it in GitHub Desktop.
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