TSL2561(照度センサ)のライブラリです

Dependents:   HYBRYD2018_IZU_ROCKET Hybrid_IZU2019

TSL2561.h

Committer:
Okamoto009
Date:
2019-02-26
Revision:
4:c1e82279b4bb
Parent:
3:f62d7ea19cbb

File content as of revision 4:c1e82279b4bb:

#ifndef TSL2561_H
#define TSL2561_H

#define TSL_SLV_ADDR_OPEN   0b01110010
#define TSL_SLV_ADDR_LOW    0b01110010
#define TSL_SLV_ADDR_HIGH   0b01001010

#define COMMAND         0xA0
#define CONTROL_REG     0x00


#define POWER_UP        0x03
#define POWER_DOWN      0x00
#define RAW_DATA_LOW    0x0C
#define RAW_DATA_HIGH   0x0D
#define RAW_DATA_R_LOW  0x0E
#define RAW_DATA_R_HIGH 0x0F
#define CHECK_REG       0x0A
#define TIMING_REG      0x01;

#define ID_NUMBER       0x11
#define TIMING          0x10

class myTSL2561
{
public:

    typedef enum AD0{
        AD0_LOW  = 0,
        AD0_HIGH = 1,
        AD0_OPEN = 2
    } AD0;

    myTSL2561(I2C &i2cBus,AD0 celect = AD0_OPEN);
    
    /*******************************************************************
    TSL2561を起動させる関数
    データをとる前に起動させておく
    *******************************************************************/
    void begin();
    
    /*******************************************************************
    0が返ってきたらError
    1が返ってきたらOK
    *******************************************************************/   
    int connectCheck();         
    
    /*******************************************************************
    照度(Lux)を返してくれる関数
    引数のwait_timeには下のset_rateが返してくる値を入れてください
    @example
    
    int time;
    time = myTSL2561.set_rate(0);
    pc.printf("Lux = %d\r\n",myTSL2561.get_luminosity(time));
    *******************************************************************/
    //float getLuminous0(unsigned int wait_time);
    //int getLuminous0(unsigned int wait_time);
    int getLuminous0();
    int getLuminous1();
    int getLuminous();
    
    /*******************************************************************
    channelに入れる値によってデータの変換時間が変わる
    0:  変換時間13.7[ms]
    1: 変換時間101[ms]
    2: 変換時間402[ms]
    この時間が返ってくるので、それをget_luminosityの引数に入れる(@exampleを参照)
    *******************************************************************/
    //unsigned int setRate(int channel);
    void setRate(int channel);
    
    
private:

    I2C *i2c;
    char _addr;
    char SLV_WRITE_TSL;
    char SLV_READ_TSL;
    
    /*char power_up_cmd[2];
    char power_down_cmd[2];
    char check_cmd;
    char read_cmd;
    char timing_cmd[2];
    */
    char cmd[2], buff[2];

    //char check_read, buff[2];
    int val[2];
    //unsigned int sekigai, time;
    //float lux;
    //int lux0, lux1, lux;
    float lux0, lux1, lux;
    float ration, scale;
    
};

#endif