Skip to content

Instantly share code, notes, and snippets.

@lis186
Last active August 29, 2015 13:57
Show Gist options
  • Save lis186/9743299 to your computer and use it in GitHub Desktop.
Save lis186/9743299 to your computer and use it in GitHub Desktop.
var gpio = require("gpio");
var RaspiCam = require("raspicam");
var moment = require('moment');
var camera = new RaspiCam({
mode: 'photo',
output: timestring+'.jpg'
});
camera.on("started", function(){
console.log('started');
});
//listen for the "read" event triggered when each new photo/video is saved
camera.on("read", function(err, filename){
console.log('err:' + err);
console.log('filename:' + filename);
});
//listen for the process to exit when the timeout has been reached
camera.on("exited", function(){
console.log('exited');
});
var shutter = gpio.export(4, {
direction: "in",
interal: 100000,
ready: function() {
console.log('button in mode ready');
}
});
shutter.on("change", function(val) {
// value will report either 1 or 0 (number) when the value changes
//console.log(val);
switch(val)
{
case 0:
console.log('press');
break;
case 1:
console.log('release');
var timestring = moment().format('YYYY-MM-DD HH.MM.SS');
camera = new RaspiCam({
mode: 'photo',
output: timestring+'.jpg'
});
//to take a snapshot, start a timelapse or video recording
camera.start( );
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment