color 2.0.0.0
Main Page

Color click

Color click is a color light sensing Click boardâ„¢, featuring the popular TSC3471 integrated color sensor. It is capable of sensing red, green, and blue light components, as well as the clear light.

click Product page


Click library

  • Author : MikroE Team
  • Date : Jan 2020.
  • Type : I2C type

Software Support

We provide a library for the Color 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 Color Click driver.

Standard key functions :

  • Config Object Initialization function.

    ‍void color_cfg_setup ( color_cfg_t *cfg );

    - Initialization function.

    ‍COLOR_RETVAL color_init ( color_t *ctx, color_cfg_t *cfg );

  • Click Default Configuration function.

    ‍void color_default_cfg ( color_t *ctx );

Example key functions :

  • This function reads desired color ratio from register.

    ‍float color_read_color_ratio ( color_t *ctx, uint8_t color );

  • This function reads 3 color filters and clear filters and converts the resulting color from RGBC to HSL.

    ‍float color_get_color_value ( color_t *ctx );

  • This function determines which color is read by click sensor function has been invoked previously.

    ‍uint8_t color_get_color ( float color_value );

Examples Description

The following code demonstrates color detection/recognition functionality of the click.

The demo application is composed of two sections :

Application Init

Initializes device and driver.

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.
color_cfg_setup( &cfg );
COLOR_MAP_MIKROBUS( cfg, MIKROBUS_1 );
color_init( &color, &cfg );
color_default_cfg( &color );
is_color = 0;
}
#define COLOR_MAP_MIKROBUS(cfg, mikrobus)
Definition color.h:67
COLOR_RETVAL color_init(color_t *ctx, color_cfg_t *cfg)
Initialization function.
void color_cfg_setup(color_cfg_t *cfg)
Config Object Initialization function.
void color_default_cfg(color_t *ctx)
Click Default Configuration function.
void application_init(void)
Definition main.c:38
Click configuration structure definition.
Definition color.h:275

Application Task

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

void application_task ( void )
{
color_value = color_get_color_value( &color );
is_color = color_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 );
}
#define ORANGE_COLOR_FLAG
Definition color.h:227
#define YELLOW_COLOR_FLAG
Definition color.h:234
#define GREEN_COLOR_FLAG
Definition color.h:233
#define PINK_COLOR_FLAG
Definition color.h:229
#define BLUE_COLOR_FLAG
Definition color.h:231
#define CYAN_COLOR_FLAG
Definition color.h:232
#define PURPLE_COLOR_FLAG
Definition color.h:230
#define RED_COLOR_FLAG
Definition color.h:228
uint8_t color_get_color(float color_value)
Detect color.
float color_get_color_value(color_t *ctx)
Functions for read color value.
void application_task(void)
Definition main.c:65

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.Color

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.