18float powf(
const float x,
const float y)
20 return (
float)(pow((
double)
x, (
double)
y));
31 i2c_dev->
write(buffer, 2);
55 return (uint16_t(buffer[1]) << 8) | (uint16_t(buffer[0]) & 0xFF);
73 delay((256 - _tcs34725IntegrationTime) * 12 / 5 + 1);
95 uint8_t it,
tcs34725Gain_t gain, uint8_t addr, TwoWire* theWire, uint8_t mux_ch)
97 _tcs34725Initialised =
false;
98 _tcs34725IntegrationTime = it;
100 if (i2c_dev)
delete i2c_dev;
123 if (!i2c_dev->
begin())
return false;
127 if ((
x != 0x4d) && (
x != 0x44) && (
x != 0x10)) {
130 _tcs34725Initialised =
true;
149 if (!_tcs34725Initialised)
begin();
155 _tcs34725IntegrationTime = it;
165 if (!_tcs34725Initialised)
begin();
171 _tcs34725Gain = gain;
187 if (!_tcs34725Initialised)
begin();
196 delay((256 - _tcs34725IntegrationTime) * 12 / 5 + 1);
214 if (!_tcs34725Initialised)
begin();
232 uint16_t red, green, blue, clear;
234 uint32_t sum = clear;
242 *r = (float)red / sum * 255.0;
243 *g = (float)green / sum * 255.0;
244 *b = (float)blue / sum * 255.0;
264 if (r == 0 && g == 0 && b == 0) {
272 X = (-0.14282F * r) + (1.54924F * g) + (-0.95641F * b);
273 Y = (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
274 Z = (-0.68202F * r) + (0.77073F * g) + (0.56332F * b);
277 xc = (X) / (X +
Y + Z);
278 yc = (
Y) / (X +
Y + Z);
281 n = (xc - 0.3320F) / (0.1858F - yc);
284 cct = (449.0F *
powf(n, 3)) + (3525.0F *
powf(n, 2)) + (6823.3F * n) + 5520.33F;
287 return (uint16_t)cct;
304 uint16_t r, uint16_t g, uint16_t b, uint16_t c)
326 if ((256 - _tcs34725IntegrationTime) > 63) {
331 sat = 1024 * (256 - _tcs34725IntegrationTime);
351 if ((256 - _tcs34725IntegrationTime) <= 63) {
363 ir = (r + g + b > c) ? (r + g + b - c) / 2 : 0;
375 uint16_t cct = (3810 * (uint32_t)b2) /
398 illuminance = (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
400 return (uint16_t)illuminance;
414 r &= ~TCS34725_ENABLE_AIEN;
425 i2c_dev->
write(buffer, 1);
439 write8(0x06, high & 0xFF);
float powf(const float x, const float y)
Implements missing powf function.
Handling TCS34725 Color Sensor support (currently replace by MXColor).
#define TCS34725_ENABLE_PON
#define TCS34725_ENABLE_AEN
#define TCS34725_COMMAND_BIT
#define TCS34725_ENABLE_AIEN
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.
bool write(const uint8_t *buffer, size_t len, bool stop=true, const uint8_t *prefix_buffer=nullptr, size_t prefix_len=0)
Write a buffer or two to the I2C device. Cannot be more than maxBufferSize() bytes.
bool write_then_read(const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, bool stop=false)
Write some data, then read some data from I2C into another buffer. Cannot be more than maxBufferSize(...
bool begin(bool addr_detect=true)
Initializes and does basic address detection.