capteur d'environment

Committer:
mwilkens241
Date:
Tue Jan 24 23:25:54 2017 +0000
Revision:
1:06c9bbbdb8b0
Parent:
0:4796574af790
Child:
2:cc2c0831a763
i2c library done but not working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mwilkens241 0:4796574af790 1 // TCS34725 RGB Color I2C Sensor breakout library for F030R8 Nucleo board
mwilkens241 1:06c9bbbdb8b0 2 #include "mbed.h"
mwilkens241 0:4796574af790 3
mwilkens241 0:4796574af790 4 //These pins should be the only piece specific to the F030R8
mwilkens241 0:4796574af790 5 #define SCL PB_8
mwilkens241 0:4796574af790 6 #define SDA PB_9
mwilkens241 0:4796574af790 7
mwilkens241 0:4796574af790 8 //I2C Address
mwilkens241 0:4796574af790 9
mwilkens241 1:06c9bbbdb8b0 10 #define SENSOR_ADDR 0x52
mwilkens241 0:4796574af790 11
mwilkens241 0:4796574af790 12 //Important Registers
mwilkens241 0:4796574af790 13
mwilkens241 0:4796574af790 14 #define TCS34725_ENABLE (0x00) //for turning on the device
mwilkens241 0:4796574af790 15 #define TCS34725_ATIME (0x01) //for integration time
mwilkens241 0:4796574af790 16 #define TCS34725_CONTROL (0x0F) //for setting the gain
mwilkens241 1:06c9bbbdb8b0 17 #define TCS34725_ID (0x12)
mwilkens241 0:4796574af790 18 #define TCS34725_CDATAL (0x14) /* Clear channel data */
mwilkens241 0:4796574af790 19 #define TCS34725_CDATAH (0x15)
mwilkens241 0:4796574af790 20 #define TCS34725_RDATAL (0x16) /* Red channel data */
mwilkens241 0:4796574af790 21 #define TCS34725_RDATAH (0x17)
mwilkens241 0:4796574af790 22 #define TCS34725_GDATAL (0x18) /* Green channel data */
mwilkens241 0:4796574af790 23 #define TCS34725_GDATAH (0x19)
mwilkens241 0:4796574af790 24 #define TCS34725_BDATAL (0x1A) /* Blue channel data */
mwilkens241 0:4796574af790 25 #define TCS34725_BDATAH (0x1B)
mwilkens241 0:4796574af790 26
mwilkens241 0:4796574af790 27 //Configuration Bits
mwilkens241 0:4796574af790 28
mwilkens241 0:4796574af790 29 #define TCS34725_ENABLE_AEN (0x02) /* RGBC Enable - Writing 1 actives the ADC, 0 disables it */
mwilkens241 0:4796574af790 30 #define TCS34725_ENABLE_PON (0x01) /* Power on - Writing 1 activates the internal oscillator, 0 disables it */
mwilkens241 0:4796574af790 31 #define TCS34725_INTEGRATIONTIME_2_4MS 0xFF /**< 2.4ms - 1 cycle - Max Count: 1024 */
mwilkens241 0:4796574af790 32 #define TCS34725_INTEGRATIONTIME_24MS 0xF6 /**< 24ms - 10 cycles - Max Count: 10240 */
mwilkens241 0:4796574af790 33 #define TCS34725_INTEGRATIONTIME_50MS 0xEB /**< 50ms - 20 cycles - Max Count: 20480 */
mwilkens241 0:4796574af790 34 #define TCS34725_INTEGRATIONTIME_101MS 0xD5 /**< 101ms - 42 cycles - Max Count: 43008 */
mwilkens241 0:4796574af790 35 #define TCS34725_INTEGRATIONTIME_154MS 0xC0 /**< 154ms - 64 cycles - Max Count: 65535 */
mwilkens241 0:4796574af790 36 #define TCS34725_INTEGRATIONTIME_700MS 0x00 /**< 700ms - 256 cycles - Max Count: 65535 */
mwilkens241 0:4796574af790 37 #define TCS34725_GAIN_1X 0x00 /**< No gain */
mwilkens241 0:4796574af790 38 #define TCS34725_GAIN_4X 0x01 /**< 4x gain */
mwilkens241 0:4796574af790 39 #define TCS34725_GAIN_16X 0x02 /**< 16x gain */
mwilkens241 0:4796574af790 40 #define TCS34725_GAIN_60X 0x03 /**< 60x gain */
mwilkens241 0:4796574af790 41
mwilkens241 0:4796574af790 42 void i2cWrite8(uint8_t addr, char reg, char data);
mwilkens241 0:4796574af790 43 uint8_t i2cRead8(uint8_t addr, char reg);
mwilkens241 0:4796574af790 44 uint16_t i2cRead16(uint8_t addr, char reg);
mwilkens241 0:4796574af790 45
mwilkens241 1:06c9bbbdb8b0 46 bool TCS34725_init(char intTime, char gain);
mwilkens241 1:06c9bbbdb8b0 47 void TCS34725_config(char intTime, char gain);
mwilkens241 1:06c9bbbdb8b0 48 void TCS34725_getColor(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c);