Skip to content

Commit

Permalink
Added interrupt handling, readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Apr 25, 2013
1 parent 3bc26af commit e46d2df
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
29 changes: 29 additions & 0 deletions Adafruit_TCS34725.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,32 @@ uint16_t Adafruit_TCS34725::calculateLux(uint16_t r, uint16_t g, uint16_t b)

return (uint16_t)illuminance;
}


void Adafruit_TCS34725::setInterrupt(boolean i) {
uint8_t r = read8(TCS34725_ENABLE);
if (i) {
r |= TCS34725_ENABLE_AIEN;
} else {
r &= ~TCS34725_ENABLE_AIEN;
}
write8(TCS34725_ENABLE, r);
}

void Adafruit_TCS34725::clearInterrupt(void) {
Wire.beginTransmission(TCS34725_ADDRESS);
#if ARDUINO >= 100
Wire.write(0x66);
#else
Wire.send(0x66);
#endif
Wire.endTransmission();
}


void Adafruit_TCS34725::setIntLimits(uint16_t low, uint16_t high) {
write8(0x04, low & 0xFF);
write8(0x05, low >> 8);
write8(0x06, high & 0xFF);
write8(0x07, high >> 8);
}
12 changes: 8 additions & 4 deletions Adafruit_TCS34725.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ typedef enum
{
TCS34725_INTEGRATIONTIME_2_4MS = 0xFF, /**< 2.4ms - 1 cycle - Max Count: 1024 */
TCS34725_INTEGRATIONTIME_24MS = 0xF6, /**< 24ms - 10 cycles - Max Count: 10240 */
TCS34725_INTEGRATIONTIME_50MS = 0xEB, /**< 50ms - 20 cycles - Max Count: 20480 */
TCS34725_INTEGRATIONTIME_101MS = 0xD5, /**< 101ms - 42 cycles - Max Count: 43008 */
TCS34725_INTEGRATIONTIME_154MS = 0xC0, /**< 154ms - 64 cycles - Max Count: 65535 */
TCS34725_INTEGRATIONTIME_700MS = 0x00 /**< 700ms - 256 cycles - Max Count: 65535 */
Expand All @@ -124,16 +125,19 @@ class Adafruit_TCS34725 {
void getRawData(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c);
uint16_t calculateColorTemperature(uint16_t r, uint16_t g, uint16_t b);
uint16_t calculateLux(uint16_t r, uint16_t g, uint16_t b);
void write8 (uint8_t reg, uint32_t value);
uint8_t read8 (uint8_t reg);
uint16_t read16 (uint8_t reg);
void setInterrupt(boolean flag);
void clearInterrupt(void);
void setIntLimits(uint16_t l, uint16_t h);
void enable(void);

private:
boolean _tcs34725Initialised;
tcs34725Gain_t _tcs34725Gain;
tcs34725IntegrationTime_t _tcs34725IntegrationTime;

void write8 (uint8_t reg, uint32_t value);
uint8_t read8 (uint8_t reg);
uint16_t read16 (uint8_t reg);
void enable(void);
void disable(void);
};

Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#Adafruit TCS34725 Color Sensor Driver #

This driver is for the Adafruit TCS34725 Breakout.
------> http://www.adafruit.com/products/1334

## About this Driver ##

Adafruit invests time and resources providing this open source code. Please support Adafruit and open-source hardware by purchasing products from Adafruit!
These modules use I2C to communicate, 2 pins are required to
interface

Written by Kevin (KTOWN) Townsend for Adafruit Industries.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Kevin (KTOWN) Townsend for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution

To download. click the ZIP button in the top bar, and check this tutorial
for instructions on how to install:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

0 comments on commit e46d2df

Please sign in to comment.