UNPKG

ambient-attx4

Version:

Library to run the Ambient Module for Tessel. Detects ambient light and sound levels

31 lines (25 loc) 1.01 kB
// Any copyright is dedicated to the Public Domain. // http://creativecommons.org/publicdomain/zero/1.0/ /********************************************* This ambient module example console.logs ambient light and sound levels and whenever a specified light or sound level trigger is met. *********************************************/ var tessel = require('tessel'); var ambientlib = require('../'); // Replace '../' with 'ambient-attx4' in your own code var ambient = ambientlib.use(tessel.port['A']); ambient.on('ready', function () { // Get points of light and sound data. setInterval( function () { ambient.getLightLevel( function(err, lightdata) { if (err) throw err; ambient.getSoundLevel( function(err, sounddata) { if (err) throw err; console.log("Light level:", lightdata.toFixed(8), " ", "Sound Level:", sounddata.toFixed(8)); }); }); }, 500); // The readings will happen every .5 seconds }); ambient.on('error', function (err) { console.log(err); });