Aaron Allar / TCS3472_I2C

Dependents:   colerSenser2

Fork of TCS3472_I2C by Karl Maxwell

Embed: (wiki syntax)

« Back to documentation index

TCS3472_I2C Class Reference

TCS3472_I2C Class Reference

TCS3472_I2C class. More...

#include <TCS3472_I2C.h>

Public Member Functions

 TCS3472_I2C (PinName sda, PinName scl)
 Create TCS3472_I2C instance.
 ~TCS3472_I2C ()
 Destructor.
void getAllColors (int *readings)
 Read red, green, blue and clear values into array.
int getClearData ()
 Read clear data.
int getRedData ()
 Read red data.
int getGreenData ()
 Read green data.
int getBlueData ()
 Read blue data.
int enablePower ()
 Power ON.
int disablePower ()
 Power OFF.
bool isPowerEnabled ()
 Checks if power is on (i.e.
int enableRGBC ()
 Activates the two-channel ADC.
int disableRGBC ()
 Disables the two-channel ADC.
bool isRGBCEnabled ()
 Checks if the two-channel ADC is enabled or not.
int enablePowerAndRGBC ()
 Activates internal oscillator and two-channel ADC simultaneously (both necessary for standard operation).
int disablePowerAndRGBC ()
 Disables internal oscillator and two-channel ADC simultaneously.
int enableWait ()
 Activates the wait feature.
int disableWait ()
 Disables the wait feature.
bool isWaitEnabled ()
 Checks if wait is enabled.
int enableInterrupt ()
 Permits RGBC interrupts to be generated.
int disableInterrupt ()
 Forbids RGBC interrupts to be generated.
bool isInterruptEnabled ()
 Checks if RGBC interrupt is enabled.
int setWaitTime (const float wtime)
 Sets wait time.
float readWaitTime ()
 Reads the current wait time.
int setIntegrationTime (const float itime)
 Sets integration time.
float readIntegrationTime ()
 Reads the current integration time.
char readEnableRegister ()
 Reads the enable register byte as a char.
int readLowInterruptThreshold ()
 Reads the low trigger point for the comparison function for interrupt generation.
int readHighInterruptThreshold ()
 Reads the high trigger point for the comparison function for interrupt generation.
int setLowInterruptThreshold (const int threshold)
 Sets the low trigger point for the comparison function for interrupt generation.
int setHighInterruptThreshold (const int threshold)
 Sets the high trigger point for the comparison function for interrupt generation.
int readInterruptPersistence ()
 Returns the number of consecutive values out of range (set by the low and high thresholds) required to trigger an interrupt.
int setInterruptPersistence (const int persistence)
 Sets the number of consecutive values out of range (set by the low and high thresholds) required to trigger an interrupt.
int clearInterrupt ()
 Clears the interrupt bit, allowing normal operation to resume.
int readRGBCGain ()
 Read RGBC gain.
int setRGBCGain (const int gain)
 Sets RGBC gain.
char getDeviceID ()
 Returns Device ID.
char readStatusRegister ()
 Reads the status register byte as a char.

Detailed Description

TCS3472_I2C class.

Used to read to and write from TCS3472 color sensor.

Example:

 #include "mbed.h"
 #include "TCS3472_I2C.h"

 TCS3472_I2C rgb_sensor( p9, p10 );
 
 int main() {
     rgb_sensor.enablePowerAndRGBC();
     rgb_sensor.setIntegrationTime( 100 );

     int rgb_readings[4];
     while(1) {
         rgb_sensor.getAllColors( rgb_readings );
         printf( "red: %d, green: %d, blue: %d, clear: %d", rgb_readings[0], rgb_readings[1], rgb_readings[2], rgb_readings[3] );
         wait_ms( 100 );
     }
 }

Definition at line 46 of file TCS3472_I2C.h.


Constructor & Destructor Documentation

TCS3472_I2C ( PinName  sda,
PinName  scl 
)

Create TCS3472_I2C instance.

Parameters:
sdasda pin for I2C
sclscl pin for I2C

Definition at line 3 of file TCS3472_I2C.cpp.

~TCS3472_I2C (  )

Destructor.

Definition at line 8 of file TCS3472_I2C.cpp.


Member Function Documentation

int clearInterrupt (  )

Clears the interrupt bit, allowing normal operation to resume.

(writes 0b11100110 to the command register to clear interrupt)

Returns:
1 if successful 0 if otherwise

Definition at line 386 of file TCS3472_I2C.cpp.

int disableInterrupt (  )

Forbids RGBC interrupts to be generated.

Returns:
1 if successful 0 if otherwise

Definition at line 175 of file TCS3472_I2C.cpp.

int disablePower (  )

Power OFF.

Disables the internal oscillator.

Returns:
1 if successful 0 if otherwise

Definition at line 98 of file TCS3472_I2C.cpp.

int disablePowerAndRGBC (  )

Disables internal oscillator and two-channel ADC simultaneously.

Returns:
1 if successful 0 if otherwise

Definition at line 140 of file TCS3472_I2C.cpp.

int disableRGBC (  )

Disables the two-channel ADC.

Returns:
1 if successful 0 if otherwise

Definition at line 119 of file TCS3472_I2C.cpp.

int disableWait (  )

Disables the wait feature.

Returns:
1 if successful 0 if otherwise

Definition at line 154 of file TCS3472_I2C.cpp.

int enableInterrupt (  )

Permits RGBC interrupts to be generated.

Returns:
1 if successful 0 if otherwise

Definition at line 168 of file TCS3472_I2C.cpp.

int enablePower (  )

Power ON.

Activates the internal oscillator to permit the timers and ADC channels to operate.

Returns:
1 if successful 0 if otherwise

Definition at line 91 of file TCS3472_I2C.cpp.

int enablePowerAndRGBC (  )

Activates internal oscillator and two-channel ADC simultaneously (both necessary for standard operation).

Returns:
1 if successful 0 if otherwise

Definition at line 133 of file TCS3472_I2C.cpp.

int enableRGBC (  )

Activates the two-channel ADC.

Returns:
1 if successful 0 if otherwise

Definition at line 112 of file TCS3472_I2C.cpp.

int enableWait (  )

Activates the wait feature.

Returns:
1 if successful 0 if otherwise

Definition at line 147 of file TCS3472_I2C.cpp.

void getAllColors ( int *  readings )

Read red, green, blue and clear values into array.

Parameters:
readingsArray of four integers to store the read data

Definition at line 49 of file TCS3472_I2C.cpp.

int getBlueData (  )

Read blue data.

Returns:
Blue data reading

Definition at line 84 of file TCS3472_I2C.cpp.

int getClearData (  )

Read clear data.

Returns:
Clear data reading

Definition at line 63 of file TCS3472_I2C.cpp.

char getDeviceID (  )

Returns Device ID.

Returns:
0x44 = TCS34721 and TCS34725 0x4D = TCS34723 and TCS34727

Definition at line 442 of file TCS3472_I2C.cpp.

int getGreenData (  )

Read green data.

Returns:
Green data reading

Definition at line 77 of file TCS3472_I2C.cpp.

int getRedData (  )

Read red data.

Returns:
Red data reading

Definition at line 70 of file TCS3472_I2C.cpp.

bool isInterruptEnabled (  )

Checks if RGBC interrupt is enabled.

Returns:
1 if enabled. 0 if not enabled.

Definition at line 182 of file TCS3472_I2C.cpp.

bool isPowerEnabled (  )

Checks if power is on (i.e.

internal oscillator enabled)

Returns:
1 if power ON. 0 if power OFF.

Definition at line 105 of file TCS3472_I2C.cpp.

bool isRGBCEnabled (  )

Checks if the two-channel ADC is enabled or not.

Returns:
1 if ADC enabled. 0 if ADC not enabled.

Definition at line 126 of file TCS3472_I2C.cpp.

bool isWaitEnabled (  )

Checks if wait is enabled.

Returns:
1 if enabled. 0 if not enabled.

Definition at line 161 of file TCS3472_I2C.cpp.

char readEnableRegister (  )

Reads the enable register byte as a char.

Returns:
Enable register byte

Definition at line 231 of file TCS3472_I2C.cpp.

int readHighInterruptThreshold (  )

Reads the high trigger point for the comparison function for interrupt generation.

Returns:
High threshold value

Definition at line 242 of file TCS3472_I2C.cpp.

float readIntegrationTime (  )

Reads the current integration time.

Returns:
Integration time in milliseconds

Definition at line 195 of file TCS3472_I2C.cpp.

int readInterruptPersistence (  )

Returns the number of consecutive values out of range (set by the low and high thresholds) required to trigger an interrupt.

Returns:
interrput persistence

Definition at line 265 of file TCS3472_I2C.cpp.

int readLowInterruptThreshold (  )

Reads the low trigger point for the comparison function for interrupt generation.

Returns:
Low threshold value

Definition at line 235 of file TCS3472_I2C.cpp.

int readRGBCGain (  )

Read RGBC gain.

Returns:
RGBC gain

Definition at line 392 of file TCS3472_I2C.cpp.

char readStatusRegister (  )

Reads the status register byte as a char.

Returns:
Status register byte

Definition at line 446 of file TCS3472_I2C.cpp.

float readWaitTime (  )

Reads the current wait time.

Returns:
Wait time in milliseconds

Definition at line 217 of file TCS3472_I2C.cpp.

int setHighInterruptThreshold ( const int  threshold )

Sets the high trigger point for the comparison function for interrupt generation.

Parameters:
thresholdHigh threshold value
Returns:
1 if successful 0 if otherwise

Definition at line 257 of file TCS3472_I2C.cpp.

int setIntegrationTime ( const float  itime )

Sets integration time.

Parameters:
itimeIntegration time to set in milliseconds. Should be in the range 2.4 - 614.4ms.
Returns:
1 if successful 0 if otherwise

Definition at line 189 of file TCS3472_I2C.cpp.

int setInterruptPersistence ( const int  persistence )

Sets the number of consecutive values out of range (set by the low and high thresholds) required to trigger an interrupt.

Parameters:
persistenceValue to set. Must be 0, 1, 2, 3, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55 or 60.
Returns:
1 if successful 0 if otherwise

Definition at line 324 of file TCS3472_I2C.cpp.

int setLowInterruptThreshold ( const int  threshold )

Sets the low trigger point for the comparison function for interrupt generation.

Parameters:
thresholdLow threshold value
Returns:
1 if successful 0 if otherwise

Definition at line 249 of file TCS3472_I2C.cpp.

int setRGBCGain ( const int  gain )

Sets RGBC gain.

Parameters:
gainGain to set. Must be 1, 4, 16 or 60.
Returns:
1 if successful 0 if otherwise

Definition at line 416 of file TCS3472_I2C.cpp.

int setWaitTime ( const float  wtime )

Sets wait time.

Parameters:
wtimeWait time to set in milliseconds. Should be in the range 2.4 - 7400ms.
Returns:
1 if successful 0 if otherwise

Definition at line 202 of file TCS3472_I2C.cpp.