Skip to content

Commit 9817959

Browse files
authored
Merge pull request #22 from a18rhodes/master
Enable Low Power Mode Through the Use of Disable State
2 parents 6067902 + cc4ddf9 commit 9817959

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

Adafruit_TCS34725.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,33 @@ void Adafruit_TCS34725::enable(void)
120120
write8(TCS34725_ENABLE, TCS34725_ENABLE_PON);
121121
delay(3);
122122
write8(TCS34725_ENABLE, TCS34725_ENABLE_PON | TCS34725_ENABLE_AEN);
123+
/* Set a delay for the integration time.
124+
This is only necessary in the case where enabling and then
125+
immediately trying to read values back. This is because setting
126+
AEN triggers an automatic integration, so if a read RGBC is
127+
performed too quickly, the data is not yet valid and all 0's are
128+
returned */
129+
switch (_tcs34725IntegrationTime)
130+
{
131+
case TCS34725_INTEGRATIONTIME_2_4MS:
132+
delay(3);
133+
break;
134+
case TCS34725_INTEGRATIONTIME_24MS:
135+
delay(24);
136+
break;
137+
case TCS34725_INTEGRATIONTIME_50MS:
138+
delay(50);
139+
break;
140+
case TCS34725_INTEGRATIONTIME_101MS:
141+
delay(101);
142+
break;
143+
case TCS34725_INTEGRATIONTIME_154MS:
144+
delay(154);
145+
break;
146+
case TCS34725_INTEGRATIONTIME_700MS:
147+
delay(700);
148+
break;
149+
}
123150
}
124151

125152
/**************************************************************************/
@@ -253,6 +280,21 @@ void Adafruit_TCS34725::getRawData (uint16_t *r, uint16_t *g, uint16_t *b, uint1
253280
}
254281
}
255282

283+
/**************************************************************************/
284+
/*!
285+
@brief Reads the raw red, green, blue and clear channel values in
286+
one-shot mode (e.g., wakes from sleep, takes measurement, enters sleep)
287+
*/
288+
/**************************************************************************/
289+
void Adafruit_TCS34725::getRawDataOneShot (uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c)
290+
{
291+
if (!_tcs34725Initialised) begin();
292+
293+
enable();
294+
getRawData(r, g, b ,c);
295+
disable();
296+
}
297+
256298
/**************************************************************************/
257299
/*!
258300
@brief Converts the raw R/G/B values to color temperature in degrees

Adafruit_TCS34725.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class Adafruit_TCS34725 {
123123
void setIntegrationTime(tcs34725IntegrationTime_t it);
124124
void setGain(tcs34725Gain_t gain);
125125
void getRawData(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c);
126+
void getRawDataOneShot(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c);
126127
uint16_t calculateColorTemperature(uint16_t r, uint16_t g, uint16_t b);
127128
uint16_t calculateLux(uint16_t r, uint16_t g, uint16_t b);
128129
void write8 (uint8_t reg, uint32_t value);
@@ -132,13 +133,13 @@ class Adafruit_TCS34725 {
132133
void clearInterrupt(void);
133134
void setIntLimits(uint16_t l, uint16_t h);
134135
void enable(void);
136+
void disable(void);
135137

136138
private:
137139
boolean _tcs34725Initialised;
138140
tcs34725Gain_t _tcs34725Gain;
139141
tcs34725IntegrationTime_t _tcs34725IntegrationTime;
140142

141-
void disable(void);
142143
};
143144

144145
#endif

0 commit comments

Comments
 (0)