Coder Social home page Coder Social logo

rgb-tcs34725's Introduction

rgb-tcs34725

A JavaScript driver for the TCS34725 RGB sensor. Use it to find the red, green, blue, or clear levels of anything you point it at. The API gives you access to the raw RGBC data, color temperatures, and lux intensity. You can buy the breakout board from Adafruit.

Breakout Image

The chip also has support for threshold interrupts on the clear channel and those APIs have been implemented here but not fully tested.

Installation

npm install rgb-tcs34725

Hardware Connections to Tessel

You can connect the module to any of the ports on Tessel:

VIN -> Unconnected

GND -> GND

3V3 -> 3V3

SCL -> SCL

SDA -> SDA

INT -> GPIO 1

LED -> GPIO 2

The wiring is the same for any module port on Tessel 1 or Tessel 2.

Example Usage

var tessel = require('tessel');
var rgbLib = require('../');
var rgb = rgbLib.use(tessel.port.A);

rgb.on('ready', function() {
  
  setInterval(function() {
    rgb.getRawData(function(err, colors) {
      if (err) throw err;

      console.log('RED:', colors.red);
      console.log('GREEN:', colors.green);
      console.log('BLUE:', colors.blue);
      console.log('CLEAR:', colors.clear);
    })
  }, 1000);
});

API

Commands

library.use(hardware, callback) initializes the module on the port of a microcontroller. It returns the rgb object and the callback has the form of callback(err, rgb).

rgb.getRawData(err, colors) returns rgbc data. colors has red, green, blue, and clear properties. Each of the colors is a 16 bit number.

rgb.calculateColorTemperature(callback(err, temp)) returns the color temperature as a 16 bit number representing Kelvins. The temperature it returns is in units of Kelvin.

rgb.calculateLux(callback(err, lux)) returns the light intensity as a 16 bit number that represents the light intensity.

rgb.enable(callback(err)) enables the module to read colors. It is called automatically when the use function is called.

rgb.disable() can be used to put the module to sleep and reduce power consumption. Call rgb.enable() to wake it back up.

rgb.setIntegrationTime(time, callback) sets the amount of time integrating values from an ADC (which determines color). Longer times produce more accurate numbers at low light levels. Available times can be found with rgb.integrationTimes.

rgb.setGain(gain, callback) sets the gain of the ADC. Available gains can be found with rgb.gains.

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.