Maxim MAX44009 Industry's Lowest-Power. Ambient Light Sensor with ADC. http://www.maximintegrated.com/datasheet/index.mvp/id/7175

Dependents:   agr_dist_v2

Committer:
gizmo69the2nd
Date:
Wed Aug 07 22:45:56 2013 +0000
Revision:
0:726b77a319d8
Final version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gizmo69the2nd 0:726b77a319d8 1 /*
gizmo69the2nd 0:726b77a319d8 2 * MAX44009 Ambient Light Sensor with ADC library
gizmo69the2nd 0:726b77a319d8 3 *
gizmo69the2nd 0:726b77a319d8 4 *
gizmo69the2nd 0:726b77a319d8 5 * Copyright (c) 2013 Davy Van Belle, MIT License
gizmo69the2nd 0:726b77a319d8 6 *
gizmo69the2nd 0:726b77a319d8 7 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
gizmo69the2nd 0:726b77a319d8 8 * and associated documentation files (the "Software"), to deal in the Software without restriction,
gizmo69the2nd 0:726b77a319d8 9 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
gizmo69the2nd 0:726b77a319d8 10 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
gizmo69the2nd 0:726b77a319d8 11 * furnished to do so, subject to the following conditions:
gizmo69the2nd 0:726b77a319d8 12 *
gizmo69the2nd 0:726b77a319d8 13 * The above copyright notice and this permission notice shall be included in all copies or
gizmo69the2nd 0:726b77a319d8 14 * substantial portions of the Software.
gizmo69the2nd 0:726b77a319d8 15 *
gizmo69the2nd 0:726b77a319d8 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
gizmo69the2nd 0:726b77a319d8 17 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
gizmo69the2nd 0:726b77a319d8 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
gizmo69the2nd 0:726b77a319d8 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
gizmo69the2nd 0:726b77a319d8 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
gizmo69the2nd 0:726b77a319d8 21 */
gizmo69the2nd 0:726b77a319d8 22
gizmo69the2nd 0:726b77a319d8 23 /** @file
gizmo69the2nd 0:726b77a319d8 24 * @brief MAX44009 I2C
gizmo69the2nd 0:726b77a319d8 25 */
gizmo69the2nd 0:726b77a319d8 26
gizmo69the2nd 0:726b77a319d8 27 #ifndef MAX44009_H
gizmo69the2nd 0:726b77a319d8 28 #define MAX44009_H
gizmo69the2nd 0:726b77a319d8 29
gizmo69the2nd 0:726b77a319d8 30 #include "mbed.h"
gizmo69the2nd 0:726b77a319d8 31
gizmo69the2nd 0:726b77a319d8 32 #define INT_STATUS 0x00
gizmo69the2nd 0:726b77a319d8 33 #define INT_ENABLE 0x01
gizmo69the2nd 0:726b77a319d8 34
gizmo69the2nd 0:726b77a319d8 35 #define CONFIG 0x02
gizmo69the2nd 0:726b77a319d8 36
gizmo69the2nd 0:726b77a319d8 37 #define LUX_HIGH_B 0x03
gizmo69the2nd 0:726b77a319d8 38 #define LUX_LOW_B 0x04
gizmo69the2nd 0:726b77a319d8 39
gizmo69the2nd 0:726b77a319d8 40 #define UP_THRESH_HIGH_B 0x05
gizmo69the2nd 0:726b77a319d8 41 #define LOW_THRESH_HIGH_B 0x06
gizmo69the2nd 0:726b77a319d8 42
gizmo69the2nd 0:726b77a319d8 43 #define THRESH_TIMER 0x07
gizmo69the2nd 0:726b77a319d8 44
gizmo69the2nd 0:726b77a319d8 45
gizmo69the2nd 0:726b77a319d8 46 /** MAX44009 class
gizmo69the2nd 0:726b77a319d8 47 */
gizmo69the2nd 0:726b77a319d8 48 class MAX44009 {
gizmo69the2nd 0:726b77a319d8 49 public:
gizmo69the2nd 0:726b77a319d8 50 /** init MAX44009 class
gizmo69the2nd 0:726b77a319d8 51 * @param *i2c pointer to I2C serial interface
gizmo69the2nd 0:726b77a319d8 52 * @param addr sensor I2C address
gizmo69the2nd 0:726b77a319d8 53 */
gizmo69the2nd 0:726b77a319d8 54 MAX44009 (I2C* i2c, char addr);
gizmo69the2nd 0:726b77a319d8 55
gizmo69the2nd 0:726b77a319d8 56 /** Set configuration register for the device
gizmo69the2nd 0:726b77a319d8 57 * @param config desired configuration register bits
gizmo69the2nd 0:726b77a319d8 58 * BIT 7 - CONT: 1 = continuous mode, 0 = single measurement
gizmo69the2nd 0:726b77a319d8 59 * BIT 6 - MANUAL: 1 = CDR, TIM[2:0] set by user, 0 = CDR, TIM[2:0] set by internal autorange
gizmo69the2nd 0:726b77a319d8 60 * BIT [5:4] - Not Used
gizmo69the2nd 0:726b77a319d8 61 * BIT 3 - CDR: 1 = Current divided by 8. (High-brightness), 0 = Current not divided.
gizmo69the2nd 0:726b77a319d8 62 * BIT [2:0] - TIM: Integration Time. See datasheet.
gizmo69the2nd 0:726b77a319d8 63 */
gizmo69the2nd 0:726b77a319d8 64 void setConfig (char config);
gizmo69the2nd 0:726b77a319d8 65
gizmo69the2nd 0:726b77a319d8 66 /** Get device INT_STATUS register
gizmo69the2nd 0:726b77a319d8 67 * BIT 0 : 0 = No interrupt event occurred, 1 = Ambient light intensity is outside the threshold range.
gizmo69the2nd 0:726b77a319d8 68 */
gizmo69the2nd 0:726b77a319d8 69 char getIntStatus();
gizmo69the2nd 0:726b77a319d8 70
gizmo69the2nd 0:726b77a319d8 71 /** Set device INT_ENABLE register
gizmo69the2nd 0:726b77a319d8 72 * @param Enable BIT 0 : 0 = INT pin and INTS bit not effected if an interrupt event occurred, 1 = INT pin pulled low and INTS bit is set if interrupt occurred. /
gizmo69the2nd 0:726b77a319d8 73 */
gizmo69the2nd 0:726b77a319d8 74 void setIntEnable(bool Enable);
gizmo69the2nd 0:726b77a319d8 75
gizmo69the2nd 0:726b77a319d8 76 /** Get LUX reading from ADC
gizmo69the2nd 0:726b77a319d8 77 *
gizmo69the2nd 0:726b77a319d8 78 */
gizmo69the2nd 0:726b77a319d8 79 float getLUXReading();
gizmo69the2nd 0:726b77a319d8 80
gizmo69the2nd 0:726b77a319d8 81 /** Set upper threshold
gizmo69the2nd 0:726b77a319d8 82 * @param threshold set upper threshold value. Further info, see datasheet
gizmo69the2nd 0:726b77a319d8 83 */
gizmo69the2nd 0:726b77a319d8 84 void setUpperThres(char threshold);
gizmo69the2nd 0:726b77a319d8 85
gizmo69the2nd 0:726b77a319d8 86 /** Set lower threshold
gizmo69the2nd 0:726b77a319d8 87 * @param threshold set lower threshold value. Further info, see datasheet
gizmo69the2nd 0:726b77a319d8 88 */
gizmo69the2nd 0:726b77a319d8 89 void setLowerThres(char threshold);
gizmo69the2nd 0:726b77a319d8 90
gizmo69the2nd 0:726b77a319d8 91 /** Set Threshold time
gizmo69the2nd 0:726b77a319d8 92 * @param time set time to trigger interrupt if value is below or above threshold value. Further info, see datasheet
gizmo69the2nd 0:726b77a319d8 93 */
gizmo69the2nd 0:726b77a319d8 94 void setThresTimer(char time);
gizmo69the2nd 0:726b77a319d8 95
gizmo69the2nd 0:726b77a319d8 96 float operator= (float d);
gizmo69the2nd 0:726b77a319d8 97
gizmo69the2nd 0:726b77a319d8 98 protected:
gizmo69the2nd 0:726b77a319d8 99
gizmo69the2nd 0:726b77a319d8 100
gizmo69the2nd 0:726b77a319d8 101 private:
gizmo69the2nd 0:726b77a319d8 102 char _addr;
gizmo69the2nd 0:726b77a319d8 103 I2C *_i2c;
gizmo69the2nd 0:726b77a319d8 104
gizmo69the2nd 0:726b77a319d8 105 };
gizmo69the2nd 0:726b77a319d8 106
gizmo69the2nd 0:726b77a319d8 107 #endif