npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ambient-attx4

v0.2.11

Published

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

Downloads

154

Readme

#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