Last active
August 29, 2015 14:21
-
-
Save mattpolicastro/267fc5ad189c3c8c567b to your computer and use it in GitHub Desktop.
Window Blinds Control Flow
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 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