Color Detector

MetaEnvironment boards come equipped with a TCS34725 color detector. Enums and functions for interacting with this sensor are defined in the colordetector_tcs34725.h header file.


The TCS34725 sensor has 2 configurable parameters that affect the data range and resultion:

Parameter Description
Gain Analog signal scale
Integration Time Amount of time spent to aggregate adc values

Afer you configure the API with your desired settings, call mbl_mw_cd_tcs34725_write_config to write the changes to the detector.

#include "metawear/sensor/colordetector_tcs34725.h"

void colordetector_config(MblMwMetaWearBoard* board) {
    // set analog gain to 16x
    mbl_mw_cd_tcs34725_set_gain(board, MBL_MW_CD_TCS34725_GAIN_16X);

    // set integration time to 4.8ms
    mbl_mw_cd_tcs34725_set_integration_time(board, 4.8f);

    // write the configuration to the sensor

Color ADC

Reading the color adc values is manually triggered by calling mbl_mw_cd_tcs34725_read_adc. You can use the timer functions (see Timer section) to schedule periodic reads.

#include "metawear/core/datasignal.h"
#include "metawear/core/types.h"

void colordetector_adc_stream(MblMwMetaWearBoard* board) {
    static auto data_handler = [](const MblMwData* data) -> void {
        // Cast value to MblMwTcs34725ColorAdc*
        auto color_adc = (MblMwTcs34725ColorAdc*) data->value;
        printf("{clear: %d, red: %d, green: %d, blue: %d}", color_adc->clear,
                color_adc->red, color_adc->green, color_adc->blue);
    auto adc_signal= mbl_mw_cd_tcs34725_get_adc_data_signal(board);

    mbl_mw_datasignal_subscribe(adc_signal, data_handler);