Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.