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 :

  • Config Object Initialization function.

    void color3_cfg_setup ( color3_cfg_t *cfg );

  • Initialization function.

    COLOR3_RETVAL color3_init ( color3_t *ctx, color3_cfg_t *cfg );

Example key functions :

  • Function is used to calculate HSL color.

    float color3_get_color_value ( color3_t *ctx );

  • Function is used to figure out dominant color.

    uint8_t color3_get_color ( float color_value );

  • Function is used to apply default settings.

    void color3_set_default_settings ( color3_t *ctx );

Examples Description

This application return the color of object.

The demo application is composed of two sections :

Application Init

Initalizes I2C driver, applies default settings and makes an initial log.

void application_init ( void )
{
log_cfg_t log_cfg;
// Logger initialization.
LOG_MAP_USB_UART( log_cfg );
log_cfg.level = LOG_LEVEL_DEBUG;
log_cfg.baud = 9600;
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

Checks which color is detected by the sensor. The detected color name is being logged on the USBUART.

void application_task ( void )
{
color_value = color3_get_color_value( &color3 );
is_color = color3_get_color( color_value );
switch( is_color )
{
{
log_printf( &logger, "--- Color: ORANGE\r\n" );
break;
}
{
log_printf( &logger, "--- Color: RED\r\n" );
break;
}
{
log_printf( &logger, "--- Color: PINK\r\n" );
break;
}
{
log_printf( &logger, "--- Color: PURPLE\r\n" );
break;
}
{
log_printf( &logger, "--- Color: BLUE\r\n" );
break;
}
{
log_printf( &logger, "--- Color: CYAN\r\n" );
break;
}
{
log_printf( &logger, "--- Color: GREEN\r\n" );
break;
}
{
log_printf( &logger, "--- Color: YELLOW\r\n" );
break;
}
default:
{
break;
}
}
Delay_ms( 300 );
}

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_cfg_t
Click configuration structure definition.
Definition: color3.h:292
color3_get_color
uint8_t color3_get_color(float color_value)
Detect color.
color3_init
COLOR3_RETVAL color3_init(color3_t *ctx, color3_cfg_t *cfg)
Initialization function.
COLOR3_CYAN_COLOR_FLAG
#define COLOR3_CYAN_COLOR_FLAG
Definition: color3.h:240
COLOR3_RED_COLOR_FLAG
#define COLOR3_RED_COLOR_FLAG
Definition: color3.h:236
application_task
void application_task(void)
Definition: main.c:61
color3_get_color_value
float color3_get_color_value(color3_t *ctx)
Get color value function.
COLOR3_BLUE_COLOR_FLAG
#define COLOR3_BLUE_COLOR_FLAG
Definition: color3.h:239
color3_cfg_setup
void color3_cfg_setup(color3_cfg_t *cfg)
Config Object Initialization function.
COLOR3_YELLOW_COLOR_FLAG
#define COLOR3_YELLOW_COLOR_FLAG
Definition: color3.h:242
COLOR3_PURPLE_COLOR_FLAG
#define COLOR3_PURPLE_COLOR_FLAG
Definition: color3.h:238
COLOR3_MAP_MIKROBUS
#define COLOR3_MAP_MIKROBUS(cfg, mikrobus)
Definition: color3.h:53
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_ORANGE_COLOR_FLAG
#define COLOR3_ORANGE_COLOR_FLAG
Definition: color3.h:235
COLOR3_GREEN_COLOR_FLAG
#define COLOR3_GREEN_COLOR_FLAG
Definition: color3.h:241
COLOR3_PINK_COLOR_FLAG
#define COLOR3_PINK_COLOR_FLAG
Definition: color3.h:237