Skip to content

Instantly share code, notes, and snippets.

@kastner
Created May 1, 2013 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kastner/5493817 to your computer and use it in GitHub Desktop.
Save kastner/5493817 to your computer and use it in GitHub Desktop.
five = require("johnny-five");
board = new five.Board({ debug: false});
board.on("ready", function() {
var servo1 = five.Servo({pin: 9});
var servo2 = five.Servo({pin: 10});
var servo3 = five.Servo({pin: 11});
board.repl.inject({
servo1: servo1, s1: servo1,
servo2: servo2, s2: servo2,
servo3: servo3, s3: servo3
});
var max = 42;
var min = 20;
var range = max - min;
servo1.move(min);
servo2.move(min);
servo3.move(min);
var dance = function () {
servo1.move(parseInt((Math.random() * range)+min, 10));
servo2.move(parseInt((Math.random() * range)+min, 10));
servo3.move(parseInt((Math.random() * range)+min, 10));
};
var dancer;
start_dance = function(){
if (!dancer)
dancer = setInterval(dance, 500);
}
stop_dance = function(){
if (dancer){
clearInterval(dancer);
dancer=null;
}
}
board.repl.inject({
dance: start_dance,
chill: stop_dance
});
servo1.on("error", function () { console.log(arguments); })
servo2.on("error", function () { console.log(arguments); })
servo3.on("error", function () { console.log(arguments); })
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment