Library which provides functions to control a TAOS TSL2561 Light-To-Digital Converter via I2C.

Dependents:   TweetTest NetworkThermometer GR-PEACH_TAMORI mDot_LoRa_Connect_ABPA_Lux ... more

TSL2561_I2C.h

Committer:
karlmaxwell67
Date:
2014-04-16
Revision:
5:93782eb646de
Parent:
TCS3472_I2C.h@ 4:5d1f8d7d81ff
Child:
6:17fef2caa563

File content as of revision 5:93782eb646de:

#ifndef TSL2561_I2C_H
#define TSL2561_I2C_H
#include "mbed.h"

//Defines 
#define TSL_SLAVE_ADDRESS       0x39

#define TSL_CONTROL             0x00
#define TSL_TIMING              0x01
#define TSL_THRESHLOWLOW        0x02
#define TSL_THRESHHIGHLOW       0x04
#define TSL_INTERRUPT           0x06
#define TSL_ID                  0x0A
#define TSL_DATA0LOW            0x0C
#define TSL_DATA1LOW            0x0E

class TSL2561_I2C {
public:
    TSL2561_I2C( PinName sda, PinName scl );
    
    int getVisibleAndIR();
    int getIROnly();
    float getLux();
   
    int enablePower();
    int disablePower();
    bool isPowerEnabled();
 
    int readGain();
    int setGain( const int gain ); // gain must be either 1 or 16   
    float readIntegrationTime(); // in ms
    int setIntegrationTime( const float itime ); // itime (in ms) should be 13.7, 101 or 402.
    int readLowInterruptThreshold();
    int readHighInterruptThreshold();
    int setLowInterruptThreshold( const int threshold );
    int setHighInterruptThreshold( const int threshold );
    int readInterruptPersistence();
    int setInterruptPersistence( const int persistence ); // 0: interrupt every ADC cycle, 1-15: corresponding number of cycles until interrupt 
    int readInterruptControl();
    int setInterruptControl( const int persistence ); // 0: interrupt output disabled, 1: Level Interrupt, 2: SMBAlert compliant, 3: Test Mode
    int clearInterrupt(); // writes 0b11000000 to command register to clear interrupt
    int getPartNumber(); // 0: TSL2560, 1: TSL2561
    int getRevisionNumber();

private:
    I2C i2c;
    
    int writeSingleRegister( char address, char data );
    int writeMultipleRegisters( char address, char* data, int quantity );
    char readSingleRegister( char address );
    int readMultipleRegisters( char address, char* output, int quantity );
};

#endif