Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: openwear-lifelogger-example
Fork of TCS3472_I2C by
Revision 2:38d5187a4e7b, committed 2014-03-19
- Comitter:
- karlmaxwell67
- Date:
- Wed Mar 19 18:48:12 2014 +0000
- Parent:
- 1:70d7d9f1af01
- Child:
- 3:6a89ac4a1979
- Commit message:
- Added functions setIntegrationTime, enableWait, disableWait, enableInterrupt, disableInterrupt and setWaitTime.
Changed in this revision
| TCS3472_I2C.cpp | Show annotated file Show diff for this revision Revisions of this file |
| TCS3472_I2C.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/TCS3472_I2C.cpp Wed Mar 19 17:23:11 2014 +0000
+++ b/TCS3472_I2C.cpp Wed Mar 19 18:48:12 2014 +0000
@@ -74,4 +74,53 @@
readMultipleRegisters( BDATA, buffer, 2 );
int reading = (int)buffer[1] << 8 | (int)buffer[0];
return reading;
+}
+
+int TCS3472_I2C::setIntegrationTime( const float itime ){
+ char atime = 256 - itime / 2.4;
+ int ack = writeSingleRegister( ATIME, atime );
+ return ack;
+}
+
+int TCS3472_I2C::enableWait(){
+ char enable_old = readSingleRegister( ENABLE_REGISTER );
+ char enable_new = enable_old | 8; // sets WEN (bit 4) to 1
+ int ack = writeSingleRegister( ENABLE_REGISTER, enable_new );
+ return ack;
+}
+
+int TCS3472_I2C::disableWait(){
+ char enable_old = readSingleRegister( ENABLE_REGISTER );
+ char enable_new = enable_old & 247; // sets WEN (bit 4) to 0
+ int ack = writeSingleRegister( ENABLE_REGISTER, enable_new );
+ return ack;
+}
+
+int TCS3472_I2C::enableInterrupt(){
+ char enable_old = readSingleRegister( ENABLE_REGISTER );
+ char enable_new = enable_old | 16; // sets AIEN (bit 5) to 1
+ int ack = writeSingleRegister( ENABLE_REGISTER, enable_new );
+ return ack;
+}
+
+int TCS3472_I2C::disableInterrupt(){
+ char enable_old = readSingleRegister( ENABLE_REGISTER );
+ char enable_new = enable_old & 239; // sets AIEN (bit 5) to 0
+ int ack = writeSingleRegister( ENABLE_REGISTER, enable_new );
+ return ack;
+}
+
+int TCS3472_I2C::setWaitTime( const float time ){
+ int ack = 1;
+ char wtime = 0;
+ if ( time >= 2.4 && time <= 614.4 ){
+ ack = writeSingleRegister( CONFIGURATION_REGISTER, 0 ); // sets WLONG to 0
+ wtime = 256 - time / 2.4;
+ }
+ else if ( time > 614.4 && time <= 7400 ){
+ ack = writeSingleRegister( CONFIGURATION_REGISTER, 2 ); // sets WLONG to 1
+ wtime = 256 - ( time / 12 ) / 2.4;
+ }
+ ack = ack || writeSingleRegister( WTIME, wtime );
+ return ack;
}
\ No newline at end of file
--- a/TCS3472_I2C.h Wed Mar 19 17:23:11 2014 +0000
+++ b/TCS3472_I2C.h Wed Mar 19 18:48:12 2014 +0000
@@ -4,7 +4,11 @@
//Defines
#define SLAVE_ADDRESS 0x29
+
#define ENABLE_REGISTER 0x00
+#define ATIME 0x01
+#define WTIME 0x03
+#define CONFIGURATION_REGISTER 0x0D
#define CDATA 0x14
#define RDATA 0x16
#define GDATA 0x18
@@ -20,12 +24,18 @@
int getGreenData();
int getBlueData();
- char readEnableRegister();
+ int setIntegrationTime( const float itime ); // itime (in ms) should be in the range 2.4 - 614.4ms.
+ int enableWait();
+ int disableWait();
+ int enableInterrupt();
+ int disableInterrupt();
+ int setWaitTime( const float wtime ); // wtime (in ms) should be in the range 2.4 - 7400ms.
private:
I2C i2c_;
int enableRGBC();
+ char readEnableRegister();
int writeSingleRegister( char address, char data );
char readSingleRegister( char address );
int readMultipleRegisters( char address, char* output, int quantity );
