Giter Site home page Giter Site logo

ambient-attx4's Introduction

#Ambient 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) {
      ambient.getSoundLevel( function(err, sdata) {
        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.setLightTrigger(0.5);

  // Set a light level trigger
  // The trigger is a float between 0 and 1
  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);
  });

  // Set a sound level trigger
  // The trigger is a float between 0 and 1
  ambient.setSoundTrigger(0.1);

  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)
});

###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 Realtime. This example demonstrates the two methods for getting the ambient module's data.

License

MIT or Apache 2.0, at your option

ambient-attx4's People

Contributors

deinspanjer avatar eiriksm avatar evansimpson avatar frijol avatar jiahuang avatar johnnyman727 avatar joshsgman avatar kevinmehall avatar pmcote avatar tcr avatar tm-rampart avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.