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: Chipin_Main Test_Color LAB_10_control FINAL_PROJECT ... more
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:
-
sda sda pin for I2C scl scl 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 377 of file TCS3472_I2C.cpp.
| int disableInterrupt | ( | ) |
Forbids RGBC interrupts to be generated.
- Returns:
- 1 if successful 0 if otherwise
Definition at line 166 of file TCS3472_I2C.cpp.
| int disablePower | ( | ) |
Power OFF.
Disables the internal oscillator.
- Returns:
- 1 if successful 0 if otherwise
Definition at line 89 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 131 of file TCS3472_I2C.cpp.
| int disableRGBC | ( | ) |
Disables the two-channel ADC.
- Returns:
- 1 if successful 0 if otherwise
Definition at line 110 of file TCS3472_I2C.cpp.
| int disableWait | ( | ) |
Disables the wait feature.
- Returns:
- 1 if successful 0 if otherwise
Definition at line 145 of file TCS3472_I2C.cpp.
| int enableInterrupt | ( | ) |
Permits RGBC interrupts to be generated.
- Returns:
- 1 if successful 0 if otherwise
Definition at line 159 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 82 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 124 of file TCS3472_I2C.cpp.
| int enableRGBC | ( | ) |
Activates the two-channel ADC.
- Returns:
- 1 if successful 0 if otherwise
Definition at line 103 of file TCS3472_I2C.cpp.
| int enableWait | ( | ) |
Activates the wait feature.
- Returns:
- 1 if successful 0 if otherwise
Definition at line 138 of file TCS3472_I2C.cpp.
| void getAllColors | ( | int * | readings ) |
Read red, green, blue and clear values into array.
- Parameters:
-
readings Array of four integers to store the read data
Definition at line 43 of file TCS3472_I2C.cpp.
| int getBlueData | ( | ) |
| int getClearData | ( | ) |
| char getDeviceID | ( | ) |
Returns Device ID.
- Returns:
- 0x44 = TCS34721 and TCS34725 0x4D = TCS34723 and TCS34727
Definition at line 433 of file TCS3472_I2C.cpp.
| int getGreenData | ( | ) |
| int getRedData | ( | ) |
| bool isInterruptEnabled | ( | ) |
Checks if RGBC interrupt is enabled.
- Returns:
- 1 if enabled. 0 if not enabled.
Definition at line 173 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 96 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 117 of file TCS3472_I2C.cpp.
| bool isWaitEnabled | ( | ) |
Checks if wait is enabled.
- Returns:
- 1 if enabled. 0 if not enabled.
Definition at line 152 of file TCS3472_I2C.cpp.
| char readEnableRegister | ( | ) |
Reads the enable register byte as a char.
- Returns:
- Enable register byte
Definition at line 222 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 233 of file TCS3472_I2C.cpp.
| float readIntegrationTime | ( | ) |
Reads the current integration time.
- Returns:
- Integration time in milliseconds
Definition at line 186 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 256 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 226 of file TCS3472_I2C.cpp.
| int readRGBCGain | ( | ) |
| char readStatusRegister | ( | ) |
Reads the status register byte as a char.
- Returns:
- Status register byte
Definition at line 437 of file TCS3472_I2C.cpp.
| float readWaitTime | ( | ) |
Reads the current wait time.
- Returns:
- Wait time in milliseconds
Definition at line 208 of file TCS3472_I2C.cpp.
| int setHighInterruptThreshold | ( | const int | threshold ) |
Sets the high trigger point for the comparison function for interrupt generation.
- Parameters:
-
threshold High threshold value
- Returns:
- 1 if successful 0 if otherwise
Definition at line 248 of file TCS3472_I2C.cpp.
| int setIntegrationTime | ( | const float | itime ) |
Sets integration time.
- Parameters:
-
itime Integration time to set in milliseconds. Should be in the range 2.4 - 614.4ms.
- Returns:
- 1 if successful 0 if otherwise
Definition at line 180 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:
-
persistence Value 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 315 of file TCS3472_I2C.cpp.
| int setLowInterruptThreshold | ( | const int | threshold ) |
Sets the low trigger point for the comparison function for interrupt generation.
- Parameters:
-
threshold Low threshold value
- Returns:
- 1 if successful 0 if otherwise
Definition at line 240 of file TCS3472_I2C.cpp.
| int setRGBCGain | ( | const int | gain ) |
Sets RGBC gain.
- Parameters:
-
gain Gain to set. Must be 1, 4, 16 or 60.
- Returns:
- 1 if successful 0 if otherwise
Definition at line 407 of file TCS3472_I2C.cpp.
| int setWaitTime | ( | const float | wtime ) |
Sets wait time.
- Parameters:
-
wtime Wait time to set in milliseconds. Should be in the range 2.4 - 7400ms.
- Returns:
- 1 if successful 0 if otherwise
Definition at line 193 of file TCS3472_I2C.cpp.
Generated on Wed Jul 13 2022 12:24:58 by
1.7.2