Created
August 11, 2012 15:27
-
-
Save rmurphey/3325237 to your computer and use it in GitHub Desktop.
Motion detector
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 five = require("../lib/johnny-five.js"), | |
board, sensor, red, green, blue, piezo; | |
board = new five.Board(); | |
board.on("ready", function() { | |
var status = new five.Led(13); | |
status.on(); | |
red = new five.Led(8); | |
green = new five.Led(9); | |
blue = new five.Led(10); | |
red.off(); | |
green.on(); | |
sensor = new five.Sensor({ | |
pin: 'A5', | |
freq: 100 | |
}); | |
board.firmata.pinMode(3, board.firmata.MODES.PWM); | |
sensor.on('change', function() { | |
console.log('change', this.normalized); | |
if (this.normalized > 50) { | |
red.on(); | |
green.off(); | |
board.firmata.analogWrite(3, 956); | |
setTimeout(function() { | |
board.firmata.analogWrite(3, 0); | |
}, 500); | |
} else { | |
green.on(); | |
red.off(); | |
board.firmata.analogWrite(3, 0); | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment