Initial release of Adafruit TCS3430 Arduino library
Complete Arduino library for TCS3430 color and ALS sensor featuring: - Full register control with get/set functions and enums - Efficient bulk I2C data reading for X,Y,Z tristimulus values - Interrupt handling with configurable persistence and thresholds - 128x gain support with HGAIN bit management - Auto-zero calibration and sleep after interrupt modes - Hardware tested on Arduino Metro Mini 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
commit
b6c43c5969
11 changed files with 1019 additions and 0 deletions
13
.clang-format
Normal file
13
.clang-format
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
Language: Cpp
|
||||||
|
BasedOnStyle: Google
|
||||||
|
IndentWidth: 2
|
||||||
|
ColumnLimit: 80
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
PointerAlignment: Left
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
15
.claude/settings.local.json
Normal file
15
.claude/settings.local.json
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"allow": [
|
||||||
|
"Bash(~/bin/arduino-cli board:*)",
|
||||||
|
"Bash(python:*)",
|
||||||
|
"Bash(arduino-cli upload:*)",
|
||||||
|
"Bash(arduino-cli compile:*)",
|
||||||
|
"Bash(arduino-cli board:*)",
|
||||||
|
"Bash(arduino-cli lib examples:*)",
|
||||||
|
"WebFetch(domain:github.com)",
|
||||||
|
"WebFetch(domain:raw.githubusercontent.com)"
|
||||||
|
],
|
||||||
|
"deny": []
|
||||||
|
}
|
||||||
|
}
|
||||||
32
.github/workflows/githubci.yml
vendored
Normal file
32
.github/workflows/githubci.yml
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
name: Arduino Library CI
|
||||||
|
|
||||||
|
on: [pull_request, push, repository_dispatch]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/setup-python@v1
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
repository: adafruit/ci-arduino
|
||||||
|
path: ci
|
||||||
|
|
||||||
|
- name: pre-install
|
||||||
|
run: bash ci/actions_install.sh
|
||||||
|
|
||||||
|
- name: clang
|
||||||
|
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
|
||||||
|
|
||||||
|
- name: test platforms
|
||||||
|
run: python3 ci/build_platform.py main_platforms
|
||||||
|
|
||||||
|
- name: doxygen
|
||||||
|
env:
|
||||||
|
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
|
||||||
|
PRETTYNAME : "Adafruit TCS3430 Arduino Library"
|
||||||
|
run: bash ci/doxy_gen_and_deploy.sh
|
||||||
32
.gitignore
vendored
Normal file
32
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Arduino IDE files
|
||||||
|
*.tmp
|
||||||
|
*.bak
|
||||||
|
*~
|
||||||
|
|
||||||
|
# Build artifacts
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*.hex
|
||||||
|
*.elf
|
||||||
|
*.map
|
||||||
|
|
||||||
|
# Documentation build
|
||||||
|
docs/html/
|
||||||
|
docs/latex/
|
||||||
|
|
||||||
|
# OS files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# IDE files
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Datasheet files (don't commit PDFs/TXT)
|
||||||
|
*.pdf
|
||||||
|
*.txt
|
||||||
|
TCS3430*.pdf
|
||||||
|
TCS3430*.txt
|
||||||
|
|
||||||
|
# Test output
|
||||||
|
output.txt
|
||||||
428
Adafruit_TCS3430.cpp
Normal file
428
Adafruit_TCS3430.cpp
Normal file
|
|
@ -0,0 +1,428 @@
|
||||||
|
/*!
|
||||||
|
* @file Adafruit_TCS3430.cpp
|
||||||
|
*
|
||||||
|
* @mainpage Adafruit TCS3430 Color and ALS Sensor
|
||||||
|
*
|
||||||
|
* @section intro_sec Introduction
|
||||||
|
*
|
||||||
|
* I2C Driver for TCS3430 Color and ALS Sensor
|
||||||
|
*
|
||||||
|
* This is a library for the Adafruit TCS3430 breakout:
|
||||||
|
* http://www.adafruit.com/
|
||||||
|
*
|
||||||
|
* Adafruit invests time and resources providing this open source code,
|
||||||
|
* please support Adafruit and open-source hardware by purchasing products from
|
||||||
|
* Adafruit!
|
||||||
|
*
|
||||||
|
* @section author Author
|
||||||
|
*
|
||||||
|
* Limor 'ladyada' Fried with assistance from Claude Code
|
||||||
|
*
|
||||||
|
* @section license License
|
||||||
|
*
|
||||||
|
* BSD (see license.txt)
|
||||||
|
*
|
||||||
|
* @section HISTORY
|
||||||
|
*
|
||||||
|
* v1.0 - First release
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Adafruit_TCS3430.h"
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Instantiates a new TCS3430 class
|
||||||
|
*/
|
||||||
|
Adafruit_TCS3430::Adafruit_TCS3430() {}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Cleans up the TCS3430
|
||||||
|
*/
|
||||||
|
Adafruit_TCS3430::~Adafruit_TCS3430() {
|
||||||
|
if (i2c_dev) {
|
||||||
|
delete i2c_dev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets up the hardware and initializes I2C
|
||||||
|
* @param addr
|
||||||
|
* The I2C address to be used.
|
||||||
|
* @param theWire
|
||||||
|
* The Wire object to be used for I2C connections.
|
||||||
|
* @return True if initialization was successful, otherwise false.
|
||||||
|
*/
|
||||||
|
bool Adafruit_TCS3430::begin(uint8_t addr, TwoWire* theWire) {
|
||||||
|
if (i2c_dev) {
|
||||||
|
delete i2c_dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_dev = new Adafruit_I2CDevice(addr, theWire);
|
||||||
|
|
||||||
|
if (!i2c_dev->begin()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check chip ID
|
||||||
|
Adafruit_BusIO_Register id_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_ID);
|
||||||
|
uint8_t chip_id = id_reg.read();
|
||||||
|
if (chip_id != 0xDC) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Power on and enable ALS
|
||||||
|
if (!powerOn(true)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!ALSEnable(true)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setIntegrationCycles(uint8_t cycles) {
|
||||||
|
Adafruit_BusIO_Register atime_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_ATIME);
|
||||||
|
return atime_reg.write(cycles);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Adafruit_TCS3430::getIntegrationCycles() {
|
||||||
|
Adafruit_BusIO_Register atime_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_ATIME);
|
||||||
|
return atime_reg.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setIntegrationTime(float ms) {
|
||||||
|
uint8_t cycles = (uint8_t)((ms / 2.78) - 1);
|
||||||
|
return setIntegrationCycles(cycles);
|
||||||
|
}
|
||||||
|
|
||||||
|
float Adafruit_TCS3430::getIntegrationTime() {
|
||||||
|
uint8_t cycles = getIntegrationCycles();
|
||||||
|
return (cycles + 1) * 2.78;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::waitEnable(bool enable) {
|
||||||
|
Adafruit_BusIO_Register enable_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_ENABLE);
|
||||||
|
Adafruit_BusIO_RegisterBits wen_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&enable_reg, 1, 3);
|
||||||
|
return wen_bit.write(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::isWaitEnabled() {
|
||||||
|
Adafruit_BusIO_Register enable_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_ENABLE);
|
||||||
|
Adafruit_BusIO_RegisterBits wen_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&enable_reg, 1, 3);
|
||||||
|
return wen_bit.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::ALSEnable(bool enable) {
|
||||||
|
Adafruit_BusIO_Register enable_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_ENABLE);
|
||||||
|
Adafruit_BusIO_RegisterBits aen_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&enable_reg, 1, 1);
|
||||||
|
return aen_bit.write(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::isALSEnabled() {
|
||||||
|
Adafruit_BusIO_Register enable_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_ENABLE);
|
||||||
|
Adafruit_BusIO_RegisterBits aen_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&enable_reg, 1, 1);
|
||||||
|
return aen_bit.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::powerOn(bool enable) {
|
||||||
|
Adafruit_BusIO_Register enable_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_ENABLE);
|
||||||
|
Adafruit_BusIO_RegisterBits pon_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&enable_reg, 1, 0);
|
||||||
|
return pon_bit.write(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::isPoweredOn() {
|
||||||
|
Adafruit_BusIO_Register enable_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_ENABLE);
|
||||||
|
Adafruit_BusIO_RegisterBits pon_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&enable_reg, 1, 0);
|
||||||
|
return pon_bit.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setWaitCycles(uint8_t cycles) {
|
||||||
|
Adafruit_BusIO_Register wtime_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_WTIME);
|
||||||
|
return wtime_reg.write(cycles);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Adafruit_TCS3430::getWaitCycles() {
|
||||||
|
Adafruit_BusIO_Register wtime_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_WTIME);
|
||||||
|
return wtime_reg.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setWaitTime(float ms) {
|
||||||
|
uint8_t cycles = (uint8_t)((ms / 2.78) - 1);
|
||||||
|
return setWaitCycles(cycles);
|
||||||
|
}
|
||||||
|
|
||||||
|
float Adafruit_TCS3430::getWaitTime() {
|
||||||
|
uint8_t cycles = getWaitCycles();
|
||||||
|
return (cycles + 1) * 2.78;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setALSThresholdLow(uint16_t threshold) {
|
||||||
|
Adafruit_BusIO_Register threshold_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_AILTL, 2, LSBFIRST);
|
||||||
|
return threshold_reg.write(threshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t Adafruit_TCS3430::getALSThresholdLow() {
|
||||||
|
Adafruit_BusIO_Register threshold_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_AILTL, 2, LSBFIRST);
|
||||||
|
return threshold_reg.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setALSThresholdHigh(uint16_t threshold) {
|
||||||
|
Adafruit_BusIO_Register threshold_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_AIHTL, 2, LSBFIRST);
|
||||||
|
return threshold_reg.write(threshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t Adafruit_TCS3430::getALSThresholdHigh() {
|
||||||
|
Adafruit_BusIO_Register threshold_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_AIHTL, 2, LSBFIRST);
|
||||||
|
return threshold_reg.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setInterruptPersistence(tcs3430_pers_t persistence) {
|
||||||
|
Adafruit_BusIO_Register pers_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_PERS);
|
||||||
|
Adafruit_BusIO_RegisterBits apers_bits =
|
||||||
|
Adafruit_BusIO_RegisterBits(&pers_reg, 4, 0);
|
||||||
|
return apers_bits.write(persistence);
|
||||||
|
}
|
||||||
|
|
||||||
|
tcs3430_pers_t Adafruit_TCS3430::getInterruptPersistence() {
|
||||||
|
Adafruit_BusIO_Register pers_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_PERS);
|
||||||
|
Adafruit_BusIO_RegisterBits apers_bits =
|
||||||
|
Adafruit_BusIO_RegisterBits(&pers_reg, 4, 0);
|
||||||
|
return (tcs3430_pers_t)apers_bits.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets wait long mode
|
||||||
|
* @param enable true to enable 12x wait time multiplier
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool Adafruit_TCS3430::setWaitLong(bool enable) {
|
||||||
|
Adafruit_BusIO_Register cfg0_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG0);
|
||||||
|
Adafruit_BusIO_RegisterBits wlong_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg0_reg, 1, 2);
|
||||||
|
return wlong_bit.write(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Gets wait long mode status
|
||||||
|
* @return true if 12x wait time multiplier is enabled
|
||||||
|
*/
|
||||||
|
bool Adafruit_TCS3430::getWaitLong() {
|
||||||
|
Adafruit_BusIO_Register cfg0_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG0);
|
||||||
|
Adafruit_BusIO_RegisterBits wlong_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg0_reg, 1, 2);
|
||||||
|
return wlong_bit.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setALSMUX_IR2(bool enable) {
|
||||||
|
Adafruit_BusIO_Register cfg1_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG1);
|
||||||
|
Adafruit_BusIO_RegisterBits amux_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg1_reg, 1, 3);
|
||||||
|
return amux_bit.write(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::getALSMUX_IR2() {
|
||||||
|
Adafruit_BusIO_Register cfg1_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG1);
|
||||||
|
Adafruit_BusIO_RegisterBits amux_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg1_reg, 1, 3);
|
||||||
|
return amux_bit.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setALSGain(tcs3430_gain_t gain) {
|
||||||
|
Adafruit_BusIO_Register cfg1_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG1);
|
||||||
|
Adafruit_BusIO_RegisterBits again_bits =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg1_reg, 2, 0);
|
||||||
|
|
||||||
|
if (gain == TCS3430_GAIN_128X) {
|
||||||
|
Adafruit_BusIO_Register cfg2_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG2);
|
||||||
|
Adafruit_BusIO_RegisterBits hgain_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg2_reg, 1, 4);
|
||||||
|
if (!again_bits.write(TCS3430_GAIN_64X) || !hgain_bit.write(1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Adafruit_BusIO_Register cfg2_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG2);
|
||||||
|
Adafruit_BusIO_RegisterBits hgain_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg2_reg, 1, 4);
|
||||||
|
if (!again_bits.write(gain) || !hgain_bit.write(0)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
tcs3430_gain_t Adafruit_TCS3430::getALSGain() {
|
||||||
|
Adafruit_BusIO_Register cfg1_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG1);
|
||||||
|
Adafruit_BusIO_RegisterBits again_bits =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg1_reg, 2, 0);
|
||||||
|
|
||||||
|
Adafruit_BusIO_Register cfg2_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG2);
|
||||||
|
Adafruit_BusIO_RegisterBits hgain_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg2_reg, 1, 4);
|
||||||
|
|
||||||
|
uint8_t again_val = again_bits.read();
|
||||||
|
bool hgain_val = hgain_bit.read();
|
||||||
|
|
||||||
|
if (again_val == TCS3430_GAIN_64X && hgain_val) {
|
||||||
|
return TCS3430_GAIN_128X;
|
||||||
|
}
|
||||||
|
return (tcs3430_gain_t)again_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::isALSSaturated() {
|
||||||
|
Adafruit_BusIO_Register status_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_STATUS);
|
||||||
|
Adafruit_BusIO_RegisterBits asat_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&status_reg, 1, 7);
|
||||||
|
return asat_bit.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::clearALSSaturated() {
|
||||||
|
Adafruit_BusIO_Register status_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_STATUS);
|
||||||
|
Adafruit_BusIO_RegisterBits asat_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&status_reg, 1, 7);
|
||||||
|
return asat_bit.write(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::isALSInterrupt() {
|
||||||
|
Adafruit_BusIO_Register status_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_STATUS);
|
||||||
|
Adafruit_BusIO_RegisterBits aint_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&status_reg, 1, 4);
|
||||||
|
return aint_bit.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::clearALSInterrupt() {
|
||||||
|
Adafruit_BusIO_Register status_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_STATUS);
|
||||||
|
Adafruit_BusIO_RegisterBits aint_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&status_reg, 1, 4);
|
||||||
|
return aint_bit.write(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Adafruit_TCS3430::getData(uint16_t* x, uint16_t* y, uint16_t* z) {
|
||||||
|
uint8_t buffer[6];
|
||||||
|
Adafruit_BusIO_Register data_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CH0DATAL, 6);
|
||||||
|
data_reg.read(buffer, 6);
|
||||||
|
|
||||||
|
*z = buffer[0] | ((uint16_t)buffer[1] << 8);
|
||||||
|
*y = buffer[2] | ((uint16_t)buffer[3] << 8);
|
||||||
|
*x = buffer[4] | ((uint16_t)buffer[5] << 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setInterruptClearOnRead(bool enable) {
|
||||||
|
Adafruit_BusIO_Register cfg3_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG3);
|
||||||
|
Adafruit_BusIO_RegisterBits int_read_clear_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg3_reg, 1, 7);
|
||||||
|
return int_read_clear_bit.write(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::getInterruptClearOnRead() {
|
||||||
|
Adafruit_BusIO_Register cfg3_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG3);
|
||||||
|
Adafruit_BusIO_RegisterBits int_read_clear_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg3_reg, 1, 7);
|
||||||
|
return int_read_clear_bit.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setSleepAfterInterrupt(bool enable) {
|
||||||
|
Adafruit_BusIO_Register cfg3_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG3);
|
||||||
|
Adafruit_BusIO_RegisterBits sai_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg3_reg, 1, 4);
|
||||||
|
return sai_bit.write(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::getSleepAfterInterrupt() {
|
||||||
|
Adafruit_BusIO_Register cfg3_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_CFG3);
|
||||||
|
Adafruit_BusIO_RegisterBits sai_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&cfg3_reg, 1, 4);
|
||||||
|
return sai_bit.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setAutoZeroMode(bool enable) {
|
||||||
|
Adafruit_BusIO_Register az_config_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_AZ_CONFIG);
|
||||||
|
Adafruit_BusIO_RegisterBits az_mode_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&az_config_reg, 1, 7);
|
||||||
|
return az_mode_bit.write(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::getAutoZeroMode() {
|
||||||
|
Adafruit_BusIO_Register az_config_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_AZ_CONFIG);
|
||||||
|
Adafruit_BusIO_RegisterBits az_mode_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&az_config_reg, 1, 7);
|
||||||
|
return az_mode_bit.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::setRunAutoZeroEveryN(uint8_t n) {
|
||||||
|
Adafruit_BusIO_Register az_config_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_AZ_CONFIG);
|
||||||
|
Adafruit_BusIO_RegisterBits az_nth_bits =
|
||||||
|
Adafruit_BusIO_RegisterBits(&az_config_reg, 7, 0);
|
||||||
|
return az_nth_bits.write(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Adafruit_TCS3430::getRunAutoZeroEveryN() {
|
||||||
|
Adafruit_BusIO_Register az_config_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_AZ_CONFIG);
|
||||||
|
Adafruit_BusIO_RegisterBits az_nth_bits =
|
||||||
|
Adafruit_BusIO_RegisterBits(&az_config_reg, 7, 0);
|
||||||
|
return az_nth_bits.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::enableSaturationInt(bool enable) {
|
||||||
|
Adafruit_BusIO_Register intenab_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_INTENAB);
|
||||||
|
Adafruit_BusIO_RegisterBits asien_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&intenab_reg, 1, 7);
|
||||||
|
return asien_bit.write(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_TCS3430::enableALSInt(bool enable) {
|
||||||
|
Adafruit_BusIO_Register intenab_reg =
|
||||||
|
Adafruit_BusIO_Register(i2c_dev, TCS3430_REG_INTENAB);
|
||||||
|
Adafruit_BusIO_RegisterBits aien_bit =
|
||||||
|
Adafruit_BusIO_RegisterBits(&intenab_reg, 1, 4);
|
||||||
|
return aien_bit.write(enable);
|
||||||
|
}
|
||||||
182
Adafruit_TCS3430.h
Normal file
182
Adafruit_TCS3430.h
Normal file
|
|
@ -0,0 +1,182 @@
|
||||||
|
/*!
|
||||||
|
* @file Adafruit_TCS3430.h
|
||||||
|
*
|
||||||
|
* I2C Driver for TCS3430 Color and ALS Sensor
|
||||||
|
*
|
||||||
|
* This is a library for the Adafruit TCS3430 breakout:
|
||||||
|
* http://www.adafruit.com/
|
||||||
|
*
|
||||||
|
* Adafruit invests time and resources providing this open source code,
|
||||||
|
* please support Adafruit and open-source hardware by purchasing products from
|
||||||
|
* Adafruit!
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* BSD license (see license.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ADAFRUIT_TCS3430_H
|
||||||
|
#define _ADAFRUIT_TCS3430_H
|
||||||
|
|
||||||
|
#include <Adafruit_BusIO_Register.h>
|
||||||
|
#include <Adafruit_I2CDevice.h>
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
/*=========================================================================
|
||||||
|
I2C ADDRESS/BITS
|
||||||
|
-----------------------------------------------------------------------*/
|
||||||
|
/** Default I2C address */
|
||||||
|
#define TCS3430_DEFAULT_ADDR 0x39
|
||||||
|
/*=========================================================================*/
|
||||||
|
|
||||||
|
/*=========================================================================
|
||||||
|
REGISTER ADDRESSES
|
||||||
|
-----------------------------------------------------------------------*/
|
||||||
|
/** Enable states and interrupts */
|
||||||
|
#define TCS3430_REG_ENABLE 0x80
|
||||||
|
/** ADC integration time */
|
||||||
|
#define TCS3430_REG_ATIME 0x81
|
||||||
|
/** ALS wait time */
|
||||||
|
#define TCS3430_REG_WTIME 0x83
|
||||||
|
/** ALS interrupt low threshold low byte */
|
||||||
|
#define TCS3430_REG_AILTL 0x84
|
||||||
|
/** ALS interrupt low threshold high byte */
|
||||||
|
#define TCS3430_REG_AILTH 0x85
|
||||||
|
/** ALS interrupt high threshold low byte */
|
||||||
|
#define TCS3430_REG_AIHTL 0x86
|
||||||
|
/** ALS interrupt high threshold high byte */
|
||||||
|
#define TCS3430_REG_AIHTH 0x87
|
||||||
|
/** ALS interrupt persistence filters */
|
||||||
|
#define TCS3430_REG_PERS 0x8C
|
||||||
|
/** Configuration register zero */
|
||||||
|
#define TCS3430_REG_CFG0 0x8D
|
||||||
|
/** Configuration register one */
|
||||||
|
#define TCS3430_REG_CFG1 0x90
|
||||||
|
/** Revision ID */
|
||||||
|
#define TCS3430_REG_REVID 0x91
|
||||||
|
/** Device ID */
|
||||||
|
#define TCS3430_REG_ID 0x92
|
||||||
|
/** Device status register */
|
||||||
|
#define TCS3430_REG_STATUS 0x93
|
||||||
|
/** Z CH0 ADC low byte register */
|
||||||
|
#define TCS3430_REG_CH0DATAL 0x94
|
||||||
|
/** Z CH0 ADC high byte register */
|
||||||
|
#define TCS3430_REG_CH0DATAH 0x95
|
||||||
|
/** Y CH1 ADC low byte register */
|
||||||
|
#define TCS3430_REG_CH1DATAL 0x96
|
||||||
|
/** Y CH1 ADC high byte register */
|
||||||
|
#define TCS3430_REG_CH1DATAH 0x97
|
||||||
|
/** IR1 CH2 ADC low byte register */
|
||||||
|
#define TCS3430_REG_CH2DATAL 0x98
|
||||||
|
/** IR1 CH2 ADC high byte register */
|
||||||
|
#define TCS3430_REG_CH2DATAH 0x99
|
||||||
|
/** X or IR2 CH3 ADC low byte register */
|
||||||
|
#define TCS3430_REG_CH3DATAL 0x9A
|
||||||
|
/** X or IR2 CH3 ADC high byte register */
|
||||||
|
#define TCS3430_REG_CH3DATAH 0x9B
|
||||||
|
/** Configuration register two */
|
||||||
|
#define TCS3430_REG_CFG2 0x9F
|
||||||
|
/** Configuration register three */
|
||||||
|
#define TCS3430_REG_CFG3 0xAB
|
||||||
|
/** Auto zero configuration */
|
||||||
|
#define TCS3430_REG_AZ_CONFIG 0xD6
|
||||||
|
/** Interrupt enables */
|
||||||
|
#define TCS3430_REG_INTENAB 0xDD
|
||||||
|
/*=========================================================================*/
|
||||||
|
|
||||||
|
/** Interrupt persistence values for PERS register */
|
||||||
|
typedef enum {
|
||||||
|
TCS3430_PERS_EVERY = 0x0, ///< Every ALS cycle
|
||||||
|
TCS3430_PERS_1 = 0x1, ///< 1 consecutive ALS value out of range
|
||||||
|
TCS3430_PERS_2 = 0x2, ///< 2 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_3 = 0x3, ///< 3 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_5 = 0x4, ///< 5 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_10 = 0x5, ///< 10 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_15 = 0x6, ///< 15 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_20 = 0x7, ///< 20 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_25 = 0x8, ///< 25 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_30 = 0x9, ///< 30 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_35 = 0xA, ///< 35 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_40 = 0xB, ///< 40 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_45 = 0xC, ///< 45 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_50 = 0xD, ///< 50 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_55 = 0xE, ///< 55 consecutive ALS values out of range
|
||||||
|
TCS3430_PERS_60 = 0xF ///< 60 consecutive ALS values out of range
|
||||||
|
} tcs3430_pers_t;
|
||||||
|
|
||||||
|
/** ALS gain values for CFG1 register */
|
||||||
|
typedef enum {
|
||||||
|
TCS3430_GAIN_1X = 0x0, ///< 1x gain
|
||||||
|
TCS3430_GAIN_4X = 0x1, ///< 4x gain
|
||||||
|
TCS3430_GAIN_16X = 0x2, ///< 16x gain
|
||||||
|
TCS3430_GAIN_64X = 0x3, ///< 64x gain
|
||||||
|
TCS3430_GAIN_128X = 0x4 ///< 128x gain (requires HGAIN bit set)
|
||||||
|
} tcs3430_gain_t;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Class that stores state and functions for interacting with
|
||||||
|
* TCS3430 Color and ALS Sensor
|
||||||
|
*/
|
||||||
|
class Adafruit_TCS3430 {
|
||||||
|
public:
|
||||||
|
Adafruit_TCS3430();
|
||||||
|
~Adafruit_TCS3430();
|
||||||
|
|
||||||
|
bool begin(uint8_t addr = TCS3430_DEFAULT_ADDR, TwoWire* theWire = &Wire);
|
||||||
|
|
||||||
|
bool setIntegrationCycles(uint8_t cycles);
|
||||||
|
uint8_t getIntegrationCycles();
|
||||||
|
bool setIntegrationTime(float ms);
|
||||||
|
float getIntegrationTime();
|
||||||
|
|
||||||
|
bool setWaitCycles(uint8_t cycles);
|
||||||
|
uint8_t getWaitCycles();
|
||||||
|
bool setWaitTime(float ms);
|
||||||
|
float getWaitTime();
|
||||||
|
|
||||||
|
bool setALSThresholdLow(uint16_t threshold);
|
||||||
|
uint16_t getALSThresholdLow();
|
||||||
|
bool setALSThresholdHigh(uint16_t threshold);
|
||||||
|
uint16_t getALSThresholdHigh();
|
||||||
|
|
||||||
|
bool setInterruptPersistence(tcs3430_pers_t persistence);
|
||||||
|
tcs3430_pers_t getInterruptPersistence();
|
||||||
|
|
||||||
|
bool setWaitLong(bool enable);
|
||||||
|
bool getWaitLong();
|
||||||
|
|
||||||
|
bool setALSMUX_IR2(bool enable);
|
||||||
|
bool getALSMUX_IR2();
|
||||||
|
bool setALSGain(tcs3430_gain_t gain);
|
||||||
|
tcs3430_gain_t getALSGain();
|
||||||
|
|
||||||
|
bool isALSSaturated();
|
||||||
|
bool clearALSSaturated();
|
||||||
|
bool isALSInterrupt();
|
||||||
|
bool clearALSInterrupt();
|
||||||
|
|
||||||
|
void getData(uint16_t* x, uint16_t* y, uint16_t* z);
|
||||||
|
|
||||||
|
bool setInterruptClearOnRead(bool enable);
|
||||||
|
bool getInterruptClearOnRead();
|
||||||
|
bool setSleepAfterInterrupt(bool enable);
|
||||||
|
bool getSleepAfterInterrupt();
|
||||||
|
bool setAutoZeroMode(bool enable);
|
||||||
|
bool getAutoZeroMode();
|
||||||
|
bool setRunAutoZeroEveryN(uint8_t n);
|
||||||
|
uint8_t getRunAutoZeroEveryN();
|
||||||
|
bool enableSaturationInt(bool enable);
|
||||||
|
bool enableALSInt(bool enable);
|
||||||
|
|
||||||
|
bool waitEnable(bool enable);
|
||||||
|
bool isWaitEnabled();
|
||||||
|
bool ALSEnable(bool enable);
|
||||||
|
bool isALSEnabled();
|
||||||
|
bool powerOn(bool enable);
|
||||||
|
bool isPoweredOn();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Adafruit_I2CDevice* i2c_dev = NULL; ///< Pointer to I2C bus interface
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
57
CODE_OF_CONDUCT.md
Normal file
57
CODE_OF_CONDUCT.md
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
# Adafruit Community Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
In the interest of fostering an open and welcoming environment, we as contributors and leaders pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level or type of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
We are committed to providing a friendly, safe and welcoming environment for all.
|
||||||
|
|
||||||
|
Examples of behavior that contributes to creating and maintaining a positive environment include:
|
||||||
|
|
||||||
|
* Be kind and courteous to others
|
||||||
|
* Using welcoming and inclusive language
|
||||||
|
* Respecting the identity of every community member, including asking for their pronouns if uncertain
|
||||||
|
* Being respectful of differing viewpoints and experiences
|
||||||
|
* Collaborating with other community members
|
||||||
|
* Providing desired assistance and knowledge to other community members
|
||||||
|
* Being open to new information and ideas
|
||||||
|
* Gracefully accepting constructive criticism
|
||||||
|
* Focusing on what is best for the community
|
||||||
|
* Showing empathy towards other community members
|
||||||
|
|
||||||
|
Examples of unacceptable behavior by community members include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery and sexual attention or advances
|
||||||
|
* The use of inappropriate images, including in a community member's avatar
|
||||||
|
* The use of inappropriate language or profanity, including in a community member's nickname
|
||||||
|
* Any spamming, flaming, baiting or other attention-stealing behavior
|
||||||
|
* Excessive or unwelcome helping; answering outside the scope of the question asked
|
||||||
|
* Discussion or promotion of activities or projects that intend or pose a risk of significant harm
|
||||||
|
* Trolling, insulting/derogatory comments, and attacks of any nature
|
||||||
|
* Promoting or spreading disinformation, lies, or conspiracy theories
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information without explicit permission
|
||||||
|
* Engaging in behavior that creates an unwelcoming or uninclusive environment
|
||||||
|
* Other conduct which could reasonably be considered inappropriate
|
||||||
|
|
||||||
|
## Our Responsibilities
|
||||||
|
|
||||||
|
Project leaders are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||||
|
|
||||||
|
Project leaders have the right and responsibility to remove, edit, or reject messages, comments, commits, code, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any community member for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct and the enforcement policies listed above apply to all Adafruit Community venues. This includes but is not limited to any community spaces (both public and private), the entire Adafruit Discord server, and Adafruit GitHub repositories. Examples of Adafruit Community spaces include but are not limited to meet-ups, audio chats on the Adafruit Discord, or interaction at a conference.
|
||||||
|
|
||||||
|
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. As a community member, you are representing our community, and are expected to behave accordingly.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html, and the [Rust Code of Conduct](https://forge.rust-lang.org/policies/code-of-conduct.html).
|
||||||
|
|
||||||
|
For other projects adopting the Adafruit Community Code of Conduct, it is possible to make modifications and customizations suitable for your project. For example, contact information, or project-specific enforcement policies. Additional language or practices may also need to be added to the Code of Conduct, but should aim to be in line with the overall spirit of the Adafruit Code of Conduct.
|
||||||
|
|
||||||
|
For answers to common questions about this code of conduct, see the FAQ at https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 Adafruit Industries
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
36
README.md
Normal file
36
README.md
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# Adafruit TCS3430 Library [](https://github.com/adafruit/Adafruit_TCS3430/actions)[](http://adafruit.github.io/Adafruit_TCS3430/html/index.html)
|
||||||
|
|
||||||
|
Arduino library for the TCS3430 Color and ALS Sensor
|
||||||
|
|
||||||
|
## About the TCS3430
|
||||||
|
|
||||||
|
The TCS3430 is a high-performance color sensor with features like:
|
||||||
|
- Spectral response matching human eye tristimulus values
|
||||||
|
- I2C interface with 400 kHz support
|
||||||
|
- Programmable interrupt with persistence filter
|
||||||
|
- Low power sleep modes
|
||||||
|
- Wide dynamic range with programmable gain
|
||||||
|
- Auto-zero calibration capability
|
||||||
|
- Four photodiode channels (X, Y, Z tristimulus + IR)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Download and install the library using the Arduino Library Manager or by downloading the latest release from GitHub.
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
This library requires:
|
||||||
|
- [Adafruit BusIO](https://github.com/adafruit/Adafruit_BusIO)
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
* [Sensor Product Page](https://www.adafruit.com/product/)
|
||||||
|
* [Datasheet](https://cdn-shop.adafruit.com/product-files/5000/)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT License. See LICENSE file for details.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Contributions are welcome! Please read our [Code of Conduct](https://github.com/adafruit/Adafruit_TCS3430/blob/main/CODE_OF_CONDUCT.md) before contributing to help this project stay welcoming.
|
||||||
193
examples/test_TCS3430/test_TCS3430.ino
Normal file
193
examples/test_TCS3430/test_TCS3430.ino
Normal file
|
|
@ -0,0 +1,193 @@
|
||||||
|
/*!
|
||||||
|
* @file test_TCS3430.ino
|
||||||
|
*
|
||||||
|
* Basic test sketch for TCS3430 Color and ALS Sensor
|
||||||
|
*
|
||||||
|
* Limor 'ladyada' Fried with assistance from Claude Code
|
||||||
|
* MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Adafruit_TCS3430.h"
|
||||||
|
|
||||||
|
Adafruit_TCS3430 tcs = Adafruit_TCS3430();
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
while (!Serial)
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
Serial.println(F("TCS3430 Color and ALS Sensor Test"));
|
||||||
|
|
||||||
|
if (!tcs.begin()) {
|
||||||
|
Serial.println(F("Failed to find TCS3430 chip"));
|
||||||
|
while (1)
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(F("TCS3430 found!"));
|
||||||
|
|
||||||
|
Serial.print(F("Power on: "));
|
||||||
|
Serial.println(tcs.isPoweredOn());
|
||||||
|
Serial.print(F("ALS enabled: "));
|
||||||
|
Serial.println(tcs.isALSEnabled());
|
||||||
|
|
||||||
|
tcs.waitEnable(false);
|
||||||
|
Serial.print(F("Wait enabled: "));
|
||||||
|
Serial.println(tcs.isWaitEnabled());
|
||||||
|
|
||||||
|
tcs.setIntegrationCycles(64);
|
||||||
|
|
||||||
|
Serial.print(F("Integration cycles: "));
|
||||||
|
Serial.println(tcs.getIntegrationCycles());
|
||||||
|
Serial.print(F("Integration time: "));
|
||||||
|
Serial.print(tcs.getIntegrationTime());
|
||||||
|
Serial.println(F(" ms"));
|
||||||
|
|
||||||
|
tcs.setWaitTime(50.0);
|
||||||
|
Serial.print(F("Wait cycles: "));
|
||||||
|
Serial.println(tcs.getWaitCycles());
|
||||||
|
Serial.print(F("Wait time: "));
|
||||||
|
Serial.print(tcs.getWaitTime());
|
||||||
|
Serial.println(F(" ms"));
|
||||||
|
|
||||||
|
tcs.setALSThresholdLow(100);
|
||||||
|
tcs.setALSThresholdHigh(5000);
|
||||||
|
Serial.print(F("ALS threshold low: "));
|
||||||
|
Serial.println(tcs.getALSThresholdLow());
|
||||||
|
Serial.print(F("ALS threshold high: "));
|
||||||
|
Serial.println(tcs.getALSThresholdHigh());
|
||||||
|
|
||||||
|
tcs.setInterruptPersistence(TCS3430_PERS_5);
|
||||||
|
Serial.print(F("Interrupt persistence: "));
|
||||||
|
tcs3430_pers_t pers = tcs.getInterruptPersistence();
|
||||||
|
switch (pers) {
|
||||||
|
case TCS3430_PERS_EVERY:
|
||||||
|
Serial.println(F("Every ALS cycle"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_1:
|
||||||
|
Serial.println(F("1 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_2:
|
||||||
|
Serial.println(F("2 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_3:
|
||||||
|
Serial.println(F("3 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_5:
|
||||||
|
Serial.println(F("5 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_10:
|
||||||
|
Serial.println(F("10 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_15:
|
||||||
|
Serial.println(F("15 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_20:
|
||||||
|
Serial.println(F("20 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_25:
|
||||||
|
Serial.println(F("25 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_30:
|
||||||
|
Serial.println(F("30 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_35:
|
||||||
|
Serial.println(F("35 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_40:
|
||||||
|
Serial.println(F("40 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_45:
|
||||||
|
Serial.println(F("45 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_50:
|
||||||
|
Serial.println(F("50 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_55:
|
||||||
|
Serial.println(F("55 consecutive"));
|
||||||
|
break;
|
||||||
|
case TCS3430_PERS_60:
|
||||||
|
Serial.println(F("60 consecutive"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Serial.println(F("Unknown"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
tcs.setWaitLong(true);
|
||||||
|
Serial.print(F("Wait long: "));
|
||||||
|
Serial.println(tcs.getWaitLong() ? F("enabled (12x multiplier)")
|
||||||
|
: F("disabled"));
|
||||||
|
|
||||||
|
tcs.setALSMUX_IR2(false);
|
||||||
|
Serial.print(F("ALS MUX: "));
|
||||||
|
Serial.println(tcs.getALSMUX_IR2() ? F("IR2 channel") : F("X channel"));
|
||||||
|
|
||||||
|
tcs.setALSGain(TCS3430_GAIN_16X);
|
||||||
|
Serial.print(F("ALS gain: "));
|
||||||
|
tcs3430_gain_t gain = tcs.getALSGain();
|
||||||
|
switch (gain) {
|
||||||
|
case TCS3430_GAIN_1X:
|
||||||
|
Serial.println(F("1x"));
|
||||||
|
break;
|
||||||
|
case TCS3430_GAIN_4X:
|
||||||
|
Serial.println(F("4x"));
|
||||||
|
break;
|
||||||
|
case TCS3430_GAIN_16X:
|
||||||
|
Serial.println(F("16x"));
|
||||||
|
break;
|
||||||
|
case TCS3430_GAIN_64X:
|
||||||
|
Serial.println(F("64x"));
|
||||||
|
break;
|
||||||
|
case TCS3430_GAIN_128X:
|
||||||
|
Serial.println(F("128x"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Serial.println(F("Unknown"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
tcs.setInterruptClearOnRead(false);
|
||||||
|
Serial.print(F("Interrupt clear on read: "));
|
||||||
|
Serial.println(tcs.getInterruptClearOnRead() ? F("enabled") : F("disabled"));
|
||||||
|
|
||||||
|
tcs.setSleepAfterInterrupt(false);
|
||||||
|
Serial.print(F("Sleep after interrupt: "));
|
||||||
|
Serial.println(tcs.getSleepAfterInterrupt() ? F("enabled") : F("disabled"));
|
||||||
|
|
||||||
|
tcs.setAutoZeroMode(false);
|
||||||
|
Serial.print(F("Auto-zero mode: "));
|
||||||
|
Serial.println(tcs.getAutoZeroMode() ? F("enabled") : F("disabled"));
|
||||||
|
|
||||||
|
tcs.setRunAutoZeroEveryN(7);
|
||||||
|
Serial.print(F("Run auto-zero every N: "));
|
||||||
|
Serial.println(tcs.getRunAutoZeroEveryN());
|
||||||
|
|
||||||
|
tcs.enableALSInt(true);
|
||||||
|
tcs.enableSaturationInt(true);
|
||||||
|
Serial.println(F("ALS and saturation interrupts enabled"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
if (tcs.isALSSaturated()) {
|
||||||
|
Serial.println(F("ALS saturated - clearing"));
|
||||||
|
tcs.clearALSSaturated();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tcs.isALSInterrupt()) {
|
||||||
|
Serial.println(F("ALS interrupt - clearing"));
|
||||||
|
tcs.clearALSInterrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t x, y, z;
|
||||||
|
tcs.getData(&x, &y, &z);
|
||||||
|
Serial.print(F("X: "));
|
||||||
|
Serial.print(x);
|
||||||
|
Serial.print(F(", Y: "));
|
||||||
|
Serial.print(y);
|
||||||
|
Serial.print(F(", Z: "));
|
||||||
|
Serial.println(z);
|
||||||
|
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
10
library.properties
Normal file
10
library.properties
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
name=Adafruit TCS3430 Library
|
||||||
|
version=1.0.0
|
||||||
|
author=Adafruit
|
||||||
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
|
sentence=Arduino library for TCS3430 color and ALS sensor
|
||||||
|
paragraph=This library provides an interface for the TCS3430 color and ambient light sensor. The TCS3430 features spectral response matching human eye tristimulus values with programmable gain, interrupt capabilities, and auto-zero calibration.
|
||||||
|
category=Sensors
|
||||||
|
url=https://github.com/adafruit/Adafruit_TCS3430
|
||||||
|
architectures=*
|
||||||
|
depends=Adafruit BusIO
|
||||||
Loading…
Reference in a new issue