color3  2.0.0.0
Main Page

Color 3 Click

Color 3 Click is a mikroBUS™ add-on board with a TCS3771 color sensor (also known as a light-to-digital converter) and a narrow beam Infrared LED. The circuit can also function as a proximity sensor

Click Product page


Click library

  • Author : MikroE Team
  • Date : Dec 2019.
  • Type : I2C type

Software Support

We provide a library for the Color3 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly form compilers IDE(recommended way), or downloaded from our LibStock, or found on mikroE github account.

Library Description

This library contains API for Color3 Click driver.

Standard key functions :

Example key functions :

Examples Description

This example demonstrates the use of Color 3 Click board by reading data

from RGBC channels and converting them to HSL color and displaying those data as well as the detected color name on the USB UART.

The demo application is composed of two sections :

Application Init

Initializes the driver and performs the Click default configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
// Click initialization.
COLOR3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
color3_init( &color3, &cfg );
Delay_ms ( 100 );
Delay_ms ( 1000 );
log_printf( &logger, "-----------------\r\n" );
log_printf( &logger, " Color 3 Click \r\n" );
log_printf( &logger, "-----------------\r\n" );
}

Application Task

Reads the values of all channels and converts them to HSL color and displays those data

as well as the detected color name on the USB UART every 500ms approximately.

void application_task ( void )
{
if ( COLOR3_OK == color3_get_rgbc_data ( &color3, &rgbc ) )
{
color3_rgbc_to_hsl ( &color3, &rgbc, &hsl );
log_printf ( &logger, "\r\n Red: %u\r\n", rgbc.red );
log_printf ( &logger, " Green: %u\r\n", rgbc.green );
log_printf ( &logger, " Blue: %u\r\n", rgbc.blue );
log_printf ( &logger, " Clear: %u\r\n", rgbc.clear );
log_printf ( &logger, " Hue: %.1f deg\r\n", hsl.hue );
log_printf ( &logger, " Saturation: %.1f %%\r\n", hsl.saturation );
log_printf ( &logger, " Lightness: %.1f %%\r\n", hsl.lightness );
log_printf ( &logger, " Dominated color: " );
switch ( color3_get_color ( &hsl ) )
{
{
log_printf ( &logger, "RED\r\n" );
break;
}
{
log_printf ( &logger, "YELLOW\r\n" );
break;
}
{
log_printf ( &logger, "GREEN\r\n" );
break;
}
{
log_printf ( &logger, "CYAN\r\n" );
break;
}
{
log_printf ( &logger, "BLUE\r\n" );
break;
}
{
log_printf ( &logger, "MAGENTA\r\n" );
break;
}
{
log_printf ( &logger, "WHITE\r\n" );
break;
}
{
log_printf ( &logger, "BLACK\r\n" );
break;
}
default:
{
log_printf ( &logger, "UNKNOWN\r\n" );
break;
}
}
}
Delay_ms ( 500 );
}

The full application code, and ready to use projects can be installed directly form compilers IDE(recommneded) or found on LibStock page or mikroE GitHub accaunt.

Other mikroE Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.Color3

Additional notes and informations

Depending on the development board you are using, you may need USB UART Click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. The terminal available in all Mikroelektronika compilers, or any other terminal application of your choice, can be used to read the message.


color3_get_rgbc_data
err_t color3_get_rgbc_data(color3_t *ctx, color3_channels_t *channels)
Color 3 get rgbc data function.
color3_get_color
uint8_t color3_get_color(color3_hsl_t *hsl)
Color 3 get color function.
COLOR3_MAGENTA_COLOR
#define COLOR3_MAGENTA_COLOR
Definition: color3.h:253
color3_cfg_t
Click configuration structure definition.
Definition: color3.h:305
COLOR3_BLUE_COLOR
#define COLOR3_BLUE_COLOR
Definition: color3.h:252
COLOR3_CYAN_COLOR
#define COLOR3_CYAN_COLOR
Definition: color3.h:251
COLOR3_OK
#define COLOR3_OK
Definition: color3.h:77
color3_hsl_t::saturation
float saturation
Definition: color3.h:339
color3_rgbc_to_hsl
void color3_rgbc_to_hsl(color3_t *ctx, color3_channels_t *rgbc, color3_hsl_t *hsl)
Color 3 rgbc to hsl function.
color3_channels_t
Color 3 RGBC channels data object.
Definition: color3.h:324
color3_channels_t::blue
uint16_t blue
Definition: color3.h:327
color3_channels_t::red
uint16_t red
Definition: color3.h:325
application_task
void application_task(void)
Definition: main.c:65
color3_hsl_t
Color 3 HSL color data object.
Definition: color3.h:337
COLOR3_RED_COLOR
#define COLOR3_RED_COLOR
Definition: color3.h:248
color3_init
err_t color3_init(color3_t *ctx, color3_cfg_t *cfg)
Initialization function.
color3_hsl_t::hue
float hue
Definition: color3.h:338
COLOR3_BLACK_COLOR
#define COLOR3_BLACK_COLOR
Definition: color3.h:255
COLOR3_GREEN_COLOR
#define COLOR3_GREEN_COLOR
Definition: color3.h:250
color3_t
Click ctx object definition.
Definition: color3.h:289
COLOR3_WHITE_COLOR
#define COLOR3_WHITE_COLOR
Definition: color3.h:254
COLOR3_YELLOW_COLOR
#define COLOR3_YELLOW_COLOR
Definition: color3.h:249
color3_cfg_setup
void color3_cfg_setup(color3_cfg_t *cfg)
Config Object Initialization function.
COLOR3_MAP_MIKROBUS
#define COLOR3_MAP_MIKROBUS(cfg, mikrobus)
Definition: color3.h:67
color3_set_default_settings
void color3_set_default_settings(color3_t *ctx)
Default settings function.
application_init
void application_init(void)
Definition: main.c:33
color3_channels_t::green
uint16_t green
Definition: color3.h:326
color3_hsl_t::lightness
float lightness
Definition: color3.h:340
color3_channels_t::clear
uint16_t clear
Definition: color3.h:328