MatrixMiniR4 1.1.4
Matrix Mini R4 Arduino Library API Documentation
Loading...
Searching...
No Matches
MiniR4TCS34725.h
Go to the documentation of this file.
1
5#ifndef MiniR4TCS34725_H
6#define MiniR4TCS34725_H
7
8#if ARDUINO >= 100
9# include <Arduino.h>
10#else
11# include <WProgram.h>
12#endif
13
14#include "MiniR4I2CDevice.h"
15
16#define TCS34725_ADDRESS (0x29)
17#define TCS34725_COMMAND_BIT (0x80)
18#define TCS34725_ENABLE (0x00)
19#define TCS34725_ENABLE_AIEN (0x10)
20#define TCS34725_ENABLE_WEN (0x08)
21#define TCS34725_ENABLE_AEN (0x02)
22#define TCS34725_ENABLE_PON \
23 (0x01)
25#define TCS34725_ATIME (0x01)
26#define TCS34725_WTIME (0x03)
27#define TCS34725_WTIME_2_4MS (0xFF)
28#define TCS34725_WTIME_204MS (0xAB)
29#define TCS34725_WTIME_614MS (0x00)
30#define TCS34725_AILTL (0x04)
31#define TCS34725_AILTH (0x05)
32#define TCS34725_AIHTL (0x06)
33#define TCS34725_AIHTH (0x07)
34#define TCS34725_PERS \
35 (0x0C)
37#define TCS34725_PERS_NONE (0b0000)
38#define TCS34725_PERS_1_CYCLE \
39 (0b0001)
41#define TCS34725_PERS_2_CYCLE \
42 (0b0010)
44#define TCS34725_PERS_3_CYCLE \
45 (0b0011)
47#define TCS34725_PERS_5_CYCLE \
48 (0b0100)
50#define TCS34725_PERS_10_CYCLE \
51 (0b0101)
53#define TCS34725_PERS_15_CYCLE \
54 (0b0110)
56#define TCS34725_PERS_20_CYCLE \
57 (0b0111)
59#define TCS34725_PERS_25_CYCLE \
60 (0b1000)
62#define TCS34725_PERS_30_CYCLE \
63 (0b1001)
65#define TCS34725_PERS_35_CYCLE \
66 (0b1010)
68#define TCS34725_PERS_40_CYCLE \
69 (0b1011)
71#define TCS34725_PERS_45_CYCLE \
72 (0b1100)
74#define TCS34725_PERS_50_CYCLE \
75 (0b1101)
77#define TCS34725_PERS_55_CYCLE \
78 (0b1110)
80#define TCS34725_PERS_60_CYCLE \
81 (0b1111)
83#define TCS34725_CONFIG (0x0D)
84#define TCS34725_CONFIG_WLONG \
85 (0x02)
87#define TCS34725_CONTROL (0x0F)
88#define TCS34725_ID (0x12)
89#define TCS34725_STATUS (0x13)
90#define TCS34725_STATUS_AINT (0x10)
91#define TCS34725_STATUS_AVALID \
92 (0x01)
94#define TCS34725_CDATAL (0x14)
95#define TCS34725_CDATAH (0x15)
96#define TCS34725_RDATAL (0x16)
97#define TCS34725_RDATAH (0x17)
98#define TCS34725_GDATAL (0x18)
99#define TCS34725_GDATAH (0x19)
100#define TCS34725_BDATAL (0x1A)
101#define TCS34725_BDATAH (0x1B)
104/*
105 * 60-Hz period: 16.67ms, 50-Hz period: 20ms
106 * 100ms is evenly divisible by 50Hz periods and by 60Hz periods
107 */
108#define TCS34725_INTEGRATIONTIME_2_4MS (0xFF)
109#define TCS34725_INTEGRATIONTIME_24MS (0xF6)
110#define TCS34725_INTEGRATIONTIME_50MS (0xEB)
111#define TCS34725_INTEGRATIONTIME_60MS (0xE7)
112#define TCS34725_INTEGRATIONTIME_101MS (0xD6)
113#define TCS34725_INTEGRATIONTIME_120MS (0xCE)
114#define TCS34725_INTEGRATIONTIME_154MS (0xC0)
115#define TCS34725_INTEGRATIONTIME_180MS (0xB5)
116#define TCS34725_INTEGRATIONTIME_199MS (0xAD)
117#define TCS34725_INTEGRATIONTIME_240MS (0x9C)
118#define TCS34725_INTEGRATIONTIME_300MS (0x83)
119#define TCS34725_INTEGRATIONTIME_360MS (0x6A)
120#define TCS34725_INTEGRATIONTIME_401MS (0x59)
121#define TCS34725_INTEGRATIONTIME_420MS (0x51)
122#define TCS34725_INTEGRATIONTIME_480MS (0x38)
123#define TCS34725_INTEGRATIONTIME_499MS (0x30)
124#define TCS34725_INTEGRATIONTIME_540MS (0x1F)
125#define TCS34725_INTEGRATIONTIME_600MS (0x06)
126#define TCS34725_INTEGRATIONTIME_614MS (0x00)
136
142{
143public:
146 uint8_t addr = TCS34725_ADDRESS, TwoWire* theWire = &Wire, uint8_t mux = -1);
147
148 boolean begin();
149 boolean init();
150
151 void setIntegrationTime(uint8_t it);
152 void setGain(tcs34725Gain_t gain);
153 void getRawData(uint16_t* r, uint16_t* g, uint16_t* b, uint16_t* c);
154 void getRGB(float* r, float* g, float* b);
155 void getRawDataOneShot(uint16_t* r, uint16_t* g, uint16_t* b, uint16_t* c);
156 uint16_t calculateColorTemperature(uint16_t r, uint16_t g, uint16_t b);
157 uint16_t calculateColorTemperature_dn40(uint16_t r, uint16_t g, uint16_t b, uint16_t c);
158 uint16_t calculateLux(uint16_t r, uint16_t g, uint16_t b);
159 void write8(uint8_t reg, uint8_t value);
160 uint8_t read8(uint8_t reg);
161 uint16_t read16(uint8_t reg);
162 void setInterrupt(boolean flag);
163 void clearInterrupt();
164 void setIntLimits(uint16_t l, uint16_t h);
165 void enable();
166 void disable();
167
168private:
169 MiniR4_I2CDevice* i2c_dev = NULL;
170 boolean _tcs34725Initialised;
171 tcs34725Gain_t _tcs34725Gain;
172 uint8_t _tcs34725IntegrationTime;
173};
174
175#endif
MiniR4 I2C low level functions.
tcs34725Gain_t
@ TCS34725_GAIN_16X
@ TCS34725_GAIN_4X
@ TCS34725_GAIN_1X
@ TCS34725_GAIN_60X
#define TCS34725_ADDRESS
#define TCS34725_INTEGRATIONTIME_2_4MS
Class that stores state and functions for interacting with TCS34725 Color Sensor.
void getRGB(float *r, float *g, float *b)
Read the RGB color detected by the sensor.
boolean init()
Part of begin.
uint16_t calculateLux(uint16_t r, uint16_t g, uint16_t b)
Converts the raw R/G/B values to lux.
Adafruit_TCS34725(uint8_t=TCS34725_INTEGRATIONTIME_2_4MS, tcs34725Gain_t=TCS34725_GAIN_1X, uint8_t addr=TCS34725_ADDRESS, TwoWire *theWire=&Wire, uint8_t mux=-1)
Constructor.
void clearInterrupt()
Clears inerrupt for TCS34725.
void getRawDataOneShot(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c)
Reads the raw red, green, blue and clear channel values in one-shot mode (e.g., wakes from sleep,...
uint8_t read8(uint8_t reg)
Reads an 8 bit value over I2C.
uint16_t calculateColorTemperature_dn40(uint16_t r, uint16_t g, uint16_t b, uint16_t c)
Converts the raw R/G/B values to color temperature in degrees Kelvin using the algorithm described in...
boolean begin()
Initializes I2C and configures the sensor.
uint16_t read16(uint8_t reg)
Reads a 16 bit values over I2C.
void setGain(tcs34725Gain_t gain)
Adjusts the gain on the TCS34725.
void disable()
Disables the device (putting it in lower power sleep mode)
void enable()
Enables the device.
void setIntegrationTime(uint8_t it)
Sets the integration time for the TC34725.
uint16_t calculateColorTemperature(uint16_t r, uint16_t g, uint16_t b)
Converts the raw R/G/B values to color temperature in degrees Kelvin.
void getRawData(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c)
Reads the raw red, green, blue and clear channel values.
void setIntLimits(uint16_t l, uint16_t h)
Sets inerrupt limits.
void setInterrupt(boolean flag)
Sets interrupt for TCS34725.
void write8(uint8_t reg, uint8_t value)
Writes a register and an 8 bit value over I2C.
The class which defines how we will talk to this device over I2C.