Skip to content

Instantly share code, notes, and snippets.

@davydog187
Created October 31, 2014 05:11
Show Gist options
  • Save davydog187/7cf65c8e1a242a67c71b to your computer and use it in GitHub Desktop.
Save davydog187/7cf65c8e1a242a67c71b to your computer and use it in GitHub Desktop.
var five = require("johnny-five");
var board = new five.Board();
function outputBinary(number, leds) {
var states = [
number & 1,
number & 2,
number & 4
];
for (var i = 0; i < 3; ++i) {
if (states[i]) {
leds[i].on();
} else {
leds[i].off();
}
}
}
board.on("ready", function() {
var ledLocations = [9, 10, 11];
var leds = [];
var button = new five.Button(2);
var counter = 0;
button.on("press", function() {
outputBinary(counter, leds);
++counter;
});
ledLocations.forEach(function(value) {
var led = new five.Led(value);
leds.push(led);
});
this.repl.inject({
leds: leds,
button: button
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment