Skip to content

Instantly share code, notes, and snippets.

@mscandal
Created July 27, 2014 20:27
Show Gist options
  • Select an option

  • Save mscandal/390d467742bc44493d04 to your computer and use it in GitHub Desktop.

Select an option

Save mscandal/390d467742bc44493d04 to your computer and use it in GitHub Desktop.
var five = require('johnny-five'),
board, b1, b2;
board = new five.Board();
module.exports.ready = function(callback) {
board.on('ready', function() {
b1 = new five.Button(8);
b2 = new five.Button(12);
board.repl.inject({
b1: b1,
b2: b2,
five: five
});
module.exports.button1 = function(callback) {
b1.on('down', function() {
callback('down');
});
b1.on('up', function() {
callback('up');
});
};
module.exports.button2 = function(callback) {
b2.on('down', function() {
callback('down');
});
b2.on('up', function() {
callback('up');
});
};
module.exports.wheel = function(tolerance, callback) {
var prev = 0 - tolerance;
board.analogRead(5, function(voltage) {
if(Math.abs(voltage - prev) > tolerance) {
prev = voltage;
callback(1024 - voltage);
}
});
};
callback(board);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment