UNPKG

johnny-five

Version:

The JavaScript Arduino Programming Framework.

87 lines (62 loc) 1.45 kB
# Nodeconf Compass Run with: ```bash node eg/nodeconf-compass.js ``` ```javascript var color = require("colors"), five = require("johnny-five"), colors, mag; five.Board().on("ready", function() { // Create an I2C `Magnetometer` instance mag = new five.Magnetometer(); // As the heading changes, log heading value mag.on("headingchange", function() { var log; log = (this.bearing.name + " " + Math.floor(this.heading) + "°"); console.log( log[colors[this.bearing.abbr]] ); }); }); colors = { N: "red", NbE: "red", NNE: "red", NEbN: "red", NE: "yellow", NEbE: "yellow", ENE: "yellow", EbN: "yellow", E: "green", EbS: "green", ESE: "green", SEbE: "green", SE: "green", SEbS: "cyan", SSE: "cyan", SbE: "cyan", S: "cyan", SbW: "cyan", SSW: "cyan", SWbS: "blue", SW: "blue", SWbW: "blue", WSW: "blue", WbS: "blue", W: "magenta", WbN: "magenta", WNW: "magenta", NWbW: "magenta", NW: "magenta", NWbN: "magenta", NNW: "magenta", NbW: "red" }; ``` ## Contributing All contributions must adhere to the [Idiomatic.js Style Guide](https://github.com/rwldrn/idiomatic.js), by maintaining the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/cowboy/grunt). ## License Copyright (c) 2012 Rick Waldron <waldron.rick@gmail.com> Licensed under the MIT license.