Skip to content

Instantly share code, notes, and snippets.

@Resseguie
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Resseguie/cc758c444fef4f67543a to your computer and use it in GitHub Desktop.
Save Resseguie/cc758c444fef4f67543a to your computer and use it in GitHub Desktop.
Demo sequence for showing off five.Led
var five = require("johnny-five"),
keypress = require("keypress");
var step = 0;
var demoSequence = [{
method: "pulse",
args: [1000]
}, {
method: "strobe",
args: [500]
}, {
method: "fadeIn",
args: [2000]
}, {
method: "fadeOut",
args: [5000]
}, {
method: "brightness",
args: [10]
}, {
method: "off"
}];
five.Board().on("ready", function() {
// Defaults to pin 11 (must be PWM)
var led = new five.Led(process.argv[2] || 11);
console.log("led.on()");
led.on();
// Just setting up our keyboard listener
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.setRawMode(true);
process.stdin.on("keypress", function(ch, key) {
// When a key is pressed, move to the next step of the demo sequence
if (key) {
// stop any ongoing action from previous step
led.stop();
// Call the next method in the demo sequence
var method = demoSequence[step].method;
var args = demoSequence[step].args;
console.log( "led." + method + "("+ ( args ? args.join() : "" ) + ")" );
five.Led.prototype[method].apply( led, args );
step++;
if(step == demoSequence.length){
// We're done!
process.exit(0);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment