Advertisement
Guest User

Snap Cam

a guest
Jul 3rd, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var tessel = require('tessel');
  2. var ambientlib = require('ambient-attx4');
  3. var camera = require('camera-vc0706').use(tessel.port['A']);
  4.  
  5. var ambient = ambientlib.use(tessel.port['B']);
  6.  
  7. var notificationLED1 = tessel.led[0];
  8. var notificationLED2 = tessel.led[1];
  9.  
  10. console.log('App Ready');
  11.  
  12. ambient.on('ready', function() {
  13.     console.log('Amb Ready');
  14.     //camera.on('ready', function () {
  15.         //console.log('Cam Ready');
  16.         ambient.setSoundTrigger(0.1);
  17.  
  18.         ambient.on('sound-trigger', function(data) {
  19.             ambient.clearSoundTrigger();
  20.  
  21.             console.log("Taking picture!");
  22.             notificationLED1.high();
  23.             notificationLED2.high();
  24.             camera.takePicture(function(err, image) {
  25.                 if (err) {
  26.                   console.log('error taking image', err);
  27.                 } else {
  28.                   notificationLED1.low();
  29.                   var name = 'picture-' + Math.floor(Date.now()*1000) + '.jpg';
  30.                   process.sendfile(name, image);
  31.                   console.log('Saved.');
  32.                   //After 0.5 seconds reset sound trigger
  33.                     setTimeout(function () {
  34.                         notificationLED2.low();
  35.                         ambient.setSoundTrigger(0.1);
  36.                     },1500);
  37.                 }
  38.               });
  39.  
  40.         });
  41.     //});      
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement