UNPKG

johnny-five

Version:

The JavaScript Arduino Programming Framework.

86 lines (56 loc) 1.55 kB
# Sensor Run with: ```bash node eg/sensor.js ``` ```javascript var five = require("johnny-five"), board, sensor; board = new five.Board(); board.on("ready", function() { // Create a new `sensor` hardware instance. sensor = new five.Sensor({ pin: "A0", freq: 250 }); // Inject the `sensor` hardware into // the Repl instance's context; // allows direct command line access board.repl.inject({ sensor: sensor }); // Properties // sensor.scaled // // Current value of a sensor, scaled to a value // between the lower and upper bound set by calling // scale( low, high ). // // Defaults to value between 0-255 // // Sensor Event API // "data" // // Fires when the pin is read for a value // sensor.scale([0, 100]).on("data", function() { console.log(this.value, this.raw); }); // "change" // // Aliases: "bend", "force", "slide", "touch" // // Fires when value of sensor changes // }); // Tutorials // // http://protolab.pbworks.com/w/page/19403657/TutorialSensors // http://www.dfrobot.com/wiki/index.php?title=Analog_Slide_Position_Sensor_(SKU:_DFR0053) ``` ## 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.