Skip to content

Instantly share code, notes, and snippets.

@rmurphey
Created August 11, 2012 15:27
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 rmurphey/3325237 to your computer and use it in GitHub Desktop.
Save rmurphey/3325237 to your computer and use it in GitHub Desktop.
Motion detector
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