Class which provides functions to control a TAOS TCS3472 Color Light-to-Digital Converter with IR Filter via I2C.

Dependents:   Chipin_Main Test_Color LAB_10_control FINAL_PROJECT ... more

Revision:
2:38d5187a4e7b
Parent:
1:70d7d9f1af01
Child:
3:6a89ac4a1979
--- 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