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" );
}
#define COLOR3_MAP_MIKROBUS(cfg, mikrobus)
Definition color3.h:67
void color3_set_default_settings(color3_t *ctx)
Default settings function.
void application_init(void)
Definition main.c:33

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 );
}
#define COLOR3_OK
Definition color3.h:77
#define COLOR3_WHITE_COLOR
Definition color3.h:254
#define COLOR3_BLACK_COLOR
Definition color3.h:255
#define COLOR3_CYAN_COLOR
Definition color3.h:251
#define COLOR3_MAGENTA_COLOR
Definition color3.h:253
#define COLOR3_GREEN_COLOR
Definition color3.h:250
#define COLOR3_YELLOW_COLOR
Definition color3.h:249
#define COLOR3_RED_COLOR
Definition color3.h:248
#define COLOR3_BLUE_COLOR
Definition color3.h:252
void application_task(void)
Definition main.c:65
uint16_t clear
Definition color3.h:328
uint16_t blue
Definition color3.h:327
uint16_t green
Definition color3.h:326
uint16_t red
Definition color3.h:325
float hue
Definition color3.h:338
float saturation
Definition color3.h:339
float lightness
Definition color3.h:340

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.