Skip to content

Instantly share code, notes, and snippets.

@mattpolicastro
Last active August 29, 2015 14:21
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 mattpolicastro/267fc5ad189c3c8c567b to your computer and use it in GitHub Desktop.
Save mattpolicastro/267fc5ad189c3c8c567b to your computer and use it in GitHub Desktop.
Window Blinds Control Flow
var raspi = require('raspi-io');
var five = require('johnny-five');
var board = new five.Board({
io: new raspi()
});
board.on('ready', function(){
var stopButton = new five.Button('GPIO22');
var controlButton = new five.Button('GPIO17');
var winch = new five.Servo.Continuous('GPIO18').stop();
var lowering;
stopButton.on('press', function(){
console.log('Stopped.');
winch.stop();
});
controlButton.on('press', function(){
setTimeout(function(){
if(!lowering) {
console.log('Raising.');
winch.cw();
}
}, 1000);
});
controlButton.on('hold', function(){
console.log('Lowering.');
lowering = true;
winch.ccw();
});
controlButton.on('release', function(){
if(lowering){
console.log('Stopped lowering.');
lowering = false;
winch.stop();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment