Created
October 31, 2014 05:11
-
-
Save davydog187/7cf65c8e1a242a67c71b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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