moon

Dependencies:   Hexi_OLED_SSD1351

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lum.h Source File

lum.h

00001 #ifndef lum_H
00002 #define lum_H
00003 
00004 #include "mbed.h"
00005 
00006 // Luminosity sensor, TSL2561
00007 // Address b7=0,b6=1,b5=1,b4=1,b3=0,b2=0,b1=1, b0=R/W
00008 #define TSL2561_ADDRESS_GND         (0x29 << 1)
00009 #define TSL2561_ADDRESS_FLOAT       (0x39 << 1)
00010 #define TSL2561_ADDRESS_VDD         (0x49 << 1)
00011 
00012 
00013 // Registers
00014 #define TSL2561_CONTROL             0x00 //Control of basic functions
00015 #define TSL2561_TIMING              0x01 //Integration time/gain control
00016 #define TSL2561_THRESHLOWLOW        0x02 //Low byte of low interrupt threshold
00017 #define TSL2561_THRESHHIGHLOW       0x04 //High byte of low interrupt threshold
00018 #define TSL2561_INTERRUPT           0x06 //Interrupt control
00019 #define TSL2561_CRC                 0x08 //Factory test — not a user register
00020 #define TSL2561_ID                  0x0A //Part number/ Rev ID
00021 #define TSL2561_DATA0LOW            0x0C //Low byte of ADC channel 0
00022 #define TSL2561_DATA0HIGH           0x0D //High byte of ADC channel 0
00023 #define TSL2561_DATA1LOW            0x0E //Low byte of ADC channel 1
00024 #define TSL2561_DATA1HIGH           0x0F //High byte of ADC channel 1
00025 
00026 
00027 #define TIMING_GAIN_1               (0UL << 4)
00028 #define TIMING_GAIN_16              (1UL << 4)
00029 #define TIMING_TIME_13R7            (0x0)
00030 #define TIMING_TIME_101             (0x1)
00031 #define TIMING_TIME_402             (0x2)
00032 #define TIMING_TIME_MANU            (0x3)
00033 #define TIMING_DEFAULT              (TIMING_GAIN_1 + TIMING_TIME_402)
00034 
00035 // ID 
00036 #define I_AM_TSL2561                0x50
00037 #define REG_NO_MASK                 0x0F
00038 
00039 // COMMAND 
00040 #define CMD_CMDMODE                 (1UL << 7)
00041 #define CMD_CLEAR                   (1UL << 6)
00042 #define CMD_WORD                    (1UL << 5)
00043 #define CMD_BLOCK                   (1UL << 4)
00044 #define CMD_SINGLE                  (CMD_CMDMODE)
00045 #define CMD_MULTI                   (CMD_CMDMODE + CMD_WORD)
00046 
00047 class TSL2561
00048 {
00049 public:
00050     TSL2561(PinName sda, PinName scl);      //set pinname
00051     TSL2561(PinName sda, PinName scl, uint8_t addr);
00052 
00053     TSL2561(I2C& TSL2561_i2c);
00054     TSL2561(I2C& TSL2561_i2c, uint8_t addr);
00055 
00056     float lux(void);
00057     uint8_t set_timing_reg(uint8_t parameter);    //Set timing register
00058     uint8_t read_timing_reg(void);    //Read timing register
00059     void frequency(int hz);           //Set I2C clock frequency
00060     uint8_t get_device_ID(void);           //check Device ID number
00061     uint16_t get_ID(void);           //Read ID and Revision Number
00062     void power_up(void);
00063     void power_down(void);
00064 
00065 protected:
00066     I2C *_i2c_p;
00067     I2C &_i2c;
00068 
00069     void init(void);   //initialize
00070 
00071 private:
00072     uint8_t  TSL2561_addr;
00073     uint8_t  dt[4];
00074     uint32_t ch0;
00075     uint32_t ch1;
00076     int8_t   gain;
00077     uint16_t  id_number;
00078     double   integ_time;
00079 };
00080 
00081 #endif