UNPKG

ambient-attx4

Version:

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

59 lines (40 loc) 1.48 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 () { // Set a light level trigger // The trigger is a float between 0 and 1 ambient.setLightTrigger(0.5); // Set a sound level trigger // The trigger is a float between 0 and 1 ambient.setSoundTrigger(0.1); console.log('Waiting for a bright light or a sound...'); ambient.on('light-trigger', function(data) { console.log("Our light trigger was hit:", data); // Clear the trigger so it stops firing ambient.clearLightTrigger(); //After 1.5 seconds reset light trigger setTimeout(function () { ambient.setLightTrigger(0.5); },1500); }); ambient.on('sound-trigger', function(data) { console.log("Something happened with sound: ", data); // Clear it ambient.clearSoundTrigger(); //After 1.5 seconds reset sound trigger setTimeout(function () { ambient.setSoundTrigger(0.1); },1500); }); }); ambient.on('error', function (err) { console.log(err); });