Ambient

View source on Github

Step 1

Make a directory inside your “tessel-code” folder called “ambient”, change directory into that folder, and initialize a tessel project:

mkdir ambient; cd ambient; t2 init

Step 2

Plug the ambient module into Tessel port A with the hexagon/icon side down and the electrical components on the top, then plug Tessel into your computer via USB.

Step 3

Install by typing npm install ambient-attx4 into the command line.

Step 4

Rename “index.js” to “ambient.js” and replace the file’s contents with the following:

// 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('ambient-attx4');

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

Save the file.

Step 5

In your command line, t2 run ambient.js
Watch light and sound values appear in your terminal! Try clapping or shining a flashlight at it.

Bonus: Test out setting triggers with light and sound (hint: there is an example in the ambient module’s examples folder).

To see what else you can do with the ambient module, see the module docs here.

Step 6

What else can you do with an ambient module? Try a community-created project.

What are you making? Share your invention!

If you run into any issues you can check out the ambient forums.

Fork on Github