Library for the BH1750 Digital 16-bit Serial Output Type Ambient Light Sensor IC.
Diff: BH1750.h
- Revision:
- 0:bea4477679ee
- Child:
- 1:8115dc8275eb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BH1750.h Thu Aug 10 12:47:55 2017 +0000 @@ -0,0 +1,81 @@ +#ifndef BH1750_H +#define BH1750_H + +#include "mbed.h" + +//!Library for the BH1750 Digital 16-bit Serial Output Type Ambient Light Sensor IC. + +/** + * @brief DEFAULT ADDRESS + */ +#define BH1750_ADDR_L 0x23 +#define BH1750_ADDR_H 0x5C + +/** + * @brief COMMAND REGISTERS + */ +#define BH1750_POWER_DOWN 0x00 /*!< No active state */ +#define BH1750_POWER_ON 0x01 /*!< Waiting for measurement command */ +#define BH1750_RESET 0x07 /*!< Reset Data register value. Reset command is not acceptable in Power Down mode */ +#define BH1750_CONTINUOUSLY_H_RESOLUTION_MODE 0x10 /*!< Start measurement at 1lx resolution. Measurement Time is typically 120ms */ +#define BH1750_CONTINUOUSLY_H_RESOLUTION_MODE2 0x11 /*!< Start measurement at 0.5lx resolution. Measurement Time is typically 120ms */ +#define BH1750_CONTINUOUSLY_L_RESOLUTION_MODE 0x13 /*!< Start measurement at 4lx resolution. Measurement Time is typically 16ms */ +#define BH1750_ONE_TIME_H_RESOLUTION_MODE 0x20 /*!< Start measurement at 1lx resolution. Measurement Time is typically 120ms. It is automatically set to Power Down mode after measurement */ +#define BH1750_ONE_TIME_H_RESOLUTION_MODE2 0x21 /*!< Start measurement at 0.5lx resolution. Measurement Time is typically 120ms. It is automatically set to Power Down mode after measurement */ +#define BH1750_ONE_TIME_L_RESOLUTION_MODE 0x23 /*!< Start measurement at 4lx resolution. Measurement Time is typically 16ms. It is automatically set to Power Down mode after measurement */ + + +/** + * @brief SENSITIVITY + */ +#define BH1750_SENSITIVITY_DEFAULT 0x45 /*!< Measurement Time Register by default. This is for registration of measurement time */ + + +/** + * @brief INTERNAL CONSTANTS + */ +#define BH1750_SUCCESS 0x00 +#define BH1750_FAILURE 0x01 +#define I2C_SUCCESS 0x00 + + + +/*! +[todo] +*/ +class BH1750 +{ +public: + //!Creates an instance of the class. + /*! + [todo] + */ + BH1750 ( PinName sda, PinName scl, uint32_t addr, uint32_t hz ); + + /*! + Destroys instance. + */ + ~BH1750(); + + //![todo] + /*! + [todo] + */ + + + uint32_t BH1750_PowerDown (); + uint32_t BH1750_PowerOn (); + uint32_t BH1750_ResetDataRegister (); + uint32_t BH1750_TriggerMeasurement ( uint32_t MODE ); + uint32_t BH1750_NewSensitivity ( uint8_t newSensitivity ); + uint32_t BH1750_ReadRawData ( char* myRawData ); + uint32_t BH1750_ReadLux ( float* myLux ); + + +private: + I2C i2c; + uint32_t BH1750_Addr; + uint32_t BH1750_Mode; +}; + +#endif