Library for the BH1750 Digital 16-bit Serial Output Type Ambient Light Sensor IC.
BH1750.h@0:bea4477679ee, 2017-08-10 (annotated)
- Committer:
- mcm
- Date:
- Thu Aug 10 12:47:55 2017 +0000
- Revision:
- 0:bea4477679ee
- Child:
- 1:8115dc8275eb
Library for the BH1750 Digital 16-bit Serial Output Type Ambient Light Sensor IC.; ; It is almost ready to be tested.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mcm | 0:bea4477679ee | 1 | #ifndef BH1750_H |
mcm | 0:bea4477679ee | 2 | #define BH1750_H |
mcm | 0:bea4477679ee | 3 | |
mcm | 0:bea4477679ee | 4 | #include "mbed.h" |
mcm | 0:bea4477679ee | 5 | |
mcm | 0:bea4477679ee | 6 | //!Library for the BH1750 Digital 16-bit Serial Output Type Ambient Light Sensor IC. |
mcm | 0:bea4477679ee | 7 | |
mcm | 0:bea4477679ee | 8 | /** |
mcm | 0:bea4477679ee | 9 | * @brief DEFAULT ADDRESS |
mcm | 0:bea4477679ee | 10 | */ |
mcm | 0:bea4477679ee | 11 | #define BH1750_ADDR_L 0x23 |
mcm | 0:bea4477679ee | 12 | #define BH1750_ADDR_H 0x5C |
mcm | 0:bea4477679ee | 13 | |
mcm | 0:bea4477679ee | 14 | /** |
mcm | 0:bea4477679ee | 15 | * @brief COMMAND REGISTERS |
mcm | 0:bea4477679ee | 16 | */ |
mcm | 0:bea4477679ee | 17 | #define BH1750_POWER_DOWN 0x00 /*!< No active state */ |
mcm | 0:bea4477679ee | 18 | #define BH1750_POWER_ON 0x01 /*!< Waiting for measurement command */ |
mcm | 0:bea4477679ee | 19 | #define BH1750_RESET 0x07 /*!< Reset Data register value. Reset command is not acceptable in Power Down mode */ |
mcm | 0:bea4477679ee | 20 | #define BH1750_CONTINUOUSLY_H_RESOLUTION_MODE 0x10 /*!< Start measurement at 1lx resolution. Measurement Time is typically 120ms */ |
mcm | 0:bea4477679ee | 21 | #define BH1750_CONTINUOUSLY_H_RESOLUTION_MODE2 0x11 /*!< Start measurement at 0.5lx resolution. Measurement Time is typically 120ms */ |
mcm | 0:bea4477679ee | 22 | #define BH1750_CONTINUOUSLY_L_RESOLUTION_MODE 0x13 /*!< Start measurement at 4lx resolution. Measurement Time is typically 16ms */ |
mcm | 0:bea4477679ee | 23 | #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 */ |
mcm | 0:bea4477679ee | 24 | #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 */ |
mcm | 0:bea4477679ee | 25 | #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 */ |
mcm | 0:bea4477679ee | 26 | |
mcm | 0:bea4477679ee | 27 | |
mcm | 0:bea4477679ee | 28 | /** |
mcm | 0:bea4477679ee | 29 | * @brief SENSITIVITY |
mcm | 0:bea4477679ee | 30 | */ |
mcm | 0:bea4477679ee | 31 | #define BH1750_SENSITIVITY_DEFAULT 0x45 /*!< Measurement Time Register by default. This is for registration of measurement time */ |
mcm | 0:bea4477679ee | 32 | |
mcm | 0:bea4477679ee | 33 | |
mcm | 0:bea4477679ee | 34 | /** |
mcm | 0:bea4477679ee | 35 | * @brief INTERNAL CONSTANTS |
mcm | 0:bea4477679ee | 36 | */ |
mcm | 0:bea4477679ee | 37 | #define BH1750_SUCCESS 0x00 |
mcm | 0:bea4477679ee | 38 | #define BH1750_FAILURE 0x01 |
mcm | 0:bea4477679ee | 39 | #define I2C_SUCCESS 0x00 |
mcm | 0:bea4477679ee | 40 | |
mcm | 0:bea4477679ee | 41 | |
mcm | 0:bea4477679ee | 42 | |
mcm | 0:bea4477679ee | 43 | /*! |
mcm | 0:bea4477679ee | 44 | [todo] |
mcm | 0:bea4477679ee | 45 | */ |
mcm | 0:bea4477679ee | 46 | class BH1750 |
mcm | 0:bea4477679ee | 47 | { |
mcm | 0:bea4477679ee | 48 | public: |
mcm | 0:bea4477679ee | 49 | //!Creates an instance of the class. |
mcm | 0:bea4477679ee | 50 | /*! |
mcm | 0:bea4477679ee | 51 | [todo] |
mcm | 0:bea4477679ee | 52 | */ |
mcm | 0:bea4477679ee | 53 | BH1750 ( PinName sda, PinName scl, uint32_t addr, uint32_t hz ); |
mcm | 0:bea4477679ee | 54 | |
mcm | 0:bea4477679ee | 55 | /*! |
mcm | 0:bea4477679ee | 56 | Destroys instance. |
mcm | 0:bea4477679ee | 57 | */ |
mcm | 0:bea4477679ee | 58 | ~BH1750(); |
mcm | 0:bea4477679ee | 59 | |
mcm | 0:bea4477679ee | 60 | //![todo] |
mcm | 0:bea4477679ee | 61 | /*! |
mcm | 0:bea4477679ee | 62 | [todo] |
mcm | 0:bea4477679ee | 63 | */ |
mcm | 0:bea4477679ee | 64 | |
mcm | 0:bea4477679ee | 65 | |
mcm | 0:bea4477679ee | 66 | uint32_t BH1750_PowerDown (); |
mcm | 0:bea4477679ee | 67 | uint32_t BH1750_PowerOn (); |
mcm | 0:bea4477679ee | 68 | uint32_t BH1750_ResetDataRegister (); |
mcm | 0:bea4477679ee | 69 | uint32_t BH1750_TriggerMeasurement ( uint32_t MODE ); |
mcm | 0:bea4477679ee | 70 | uint32_t BH1750_NewSensitivity ( uint8_t newSensitivity ); |
mcm | 0:bea4477679ee | 71 | uint32_t BH1750_ReadRawData ( char* myRawData ); |
mcm | 0:bea4477679ee | 72 | uint32_t BH1750_ReadLux ( float* myLux ); |
mcm | 0:bea4477679ee | 73 | |
mcm | 0:bea4477679ee | 74 | |
mcm | 0:bea4477679ee | 75 | private: |
mcm | 0:bea4477679ee | 76 | I2C i2c; |
mcm | 0:bea4477679ee | 77 | uint32_t BH1750_Addr; |
mcm | 0:bea4477679ee | 78 | uint32_t BH1750_Mode; |
mcm | 0:bea4477679ee | 79 | }; |
mcm | 0:bea4477679ee | 80 | |
mcm | 0:bea4477679ee | 81 | #endif |