New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ambient-attx4

Package Overview
Dependencies
Maintainers
5
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ambient-attx4

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

  • 0.2.11
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

#Ambient Code of Conduct

Driver for the ambient-attx4 Tessel ambient (light and sound detecting) module. The hardware documentation can be found here.

Use the Ambient module to gather data about the ambient light and sound levels.

The module currently supports 'streams' of light levels and sound levels, as well as trigger levels for light and sound levels. You can use triggers to get notified when, for example, a light turns on or somebody claps.

All the values received and used for triggers are between 0.0 and 1.0.

You'll notice that the light readings seem to be logarithmic - when making the ambient light brighter, the reading will increase slowly and then get faster. That's a property of the photodiode itself.

If you run into any issues you can ask for support on the Ambient Module Forums.

###Installation

npm install ambient-attx4

###Example

/*********************************************
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, ldata) {
      if (err) throw err;
      ambient.getSoundLevel( function(err, sdata) {
        if (err) throw err;
        console.log("Light level:", ldata.toFixed(8), " ", "Sound Level:", sdata.toFixed(8));
    });
  })}, 500); // The readings will happen every .5 seconds unless the trigger is hit
});

ambient.on('error', function (err) {
  console.log(err)
});

###Methods

# ambient.clearLightTrigger( callback(err, triggerVal) )
Clears trigger listener for light trigger.

# ambient.clearSoundTrigger( callback(err, triggerVal) )
Clears trigger listener for sound trigger.

# ambient.getLightBuffer( callback(err, data) )
Gets the last 10 light readings.

# ambient.getLightLevel( callback(err, data) )
Gets a single data point of light level.

# ambient.getSoundBuffer( callback(err, data) )
Gets the last 10 sound readings.

# ambient.getSoundLevel( callback(err, data) )
Gets a single data point of sound level.

# ambient.setLightTrigger( triggerVal, callback(err, triggerVal) )
Sets a trigger to emit a 'light-trigger' event when triggerVal is reached. triggerVal is a float between 0 and 1.0.

# ambient.setSoundTrigger( triggerVal, callback(err, triggerVal) )
Sets a trigger to emit a 'sound-trigger' event when triggerVal is reached. triggerVal is a float between 0 and 1.0.

###Events

# ambient.on( 'error', callback(err) )
Emitted upon error.

# ambient.on( 'light', callback(lightData) )
Get a stream of light data. Fetches data about every 500 ms and frequency can be changed here.

# ambient.on( 'light-trigger', callback(lightTriggerValue) )
Emitted upon crossing light trigger threshold.

# ambient.on( 'ready', callback() )
Emitted upon first successful communication between the Tessel and the module.

# ambient.on( 'sound', callback(soundData) )
Get a stream of sound level data. Fetches data about every 500 ms and frequency can be changed here.

# ambient.on( 'sound-trigger', callback(soundTriggerValue) )
Emitted upon crossing sound trigger threshold.

###Further Examples

  • Ambient Triggers. This example demonstrates the two methods for handling an event when the sound or light gets above a defined threshold.

License

MIT or Apache 2.0, at your option

Keywords

FAQs

Package last updated on 03 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc