color2  2.0.0.0
Main Page

Color 2 click

Color 2 click carries the ISL29125 RGB color light sensor. It detects red, green and blue in a variety of lighting conditions, outputting 16-bit resolution data in a measuring range from 5.7 m lux to 10,000 lux.

click Product page


Click library

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

Software Support

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

Standard key functions :

Example key functions :

Examples Description

This example demonstrates the use of Color 2 click board by reading data

from RGB 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.
COLOR2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
color2_init( &color2, &cfg );
if ( COLOR2_ERROR == color2_default_cfg ( &color2 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}

Application Task

Waits for the data ready interrupt, then 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 100ms approximately.

void application_task ( void )
{
// Wait for the data ready interrupt indication
while ( color2_get_int_pin ( &color2 ) );
uint8_t status = 0;
if ( ( COLOR2_OK == color2_read_status ( &color2, &status ) ) &&
( COLOR2_OK == color2_read_rgb ( &color2, &rgb ) ) )
{
color2_rgb_to_hsl ( &color2, &rgb, &hsl );
log_printf ( &logger, "\r\n Red: %u\r\n", rgb.red );
log_printf ( &logger, " Green: %u\r\n", rgb.green );
log_printf ( &logger, " Blue: %u\r\n", rgb.blue );
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 ( color2_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;
}
}
}
}

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

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.


color2_cfg_t
Click configuration structure definition.
Definition: color2.h:209
color2_hsl_t::hue
float hue
Definition: color2.h:241
COLOR2_OK
#define COLOR2_OK
Definition: color2.h:73
application_task
void application_task(void)
Definition: main.c:67
color2_rgb_t::red
uint16_t red
Definition: color2.h:229
COLOR2_GREEN_COLOR
#define COLOR2_GREEN_COLOR
Definition: color2.h:154
color2_rgb_t::green
uint16_t green
Definition: color2.h:230
COLOR2_RED_COLOR
#define COLOR2_RED_COLOR
Definition: color2.h:152
color2_cfg_setup
void color2_cfg_setup(color2_cfg_t *cfg)
Config Object Initialization function.
color2_rgb_to_hsl
void color2_rgb_to_hsl(color2_t *ctx, color2_rgb_t *rgb, color2_hsl_t *hsl)
Functions for read color value.
COLOR2_ERROR
#define COLOR2_ERROR
Definition: color2.h:74
color2_rgb_t
Color 2 RGB channels data object.
Definition: color2.h:228
color2_hsl_t
Color 2 HSL color data object.
Definition: color2.h:240
COLOR2_MAGENTA_COLOR
#define COLOR2_MAGENTA_COLOR
Definition: color2.h:157
COLOR2_BLUE_COLOR
#define COLOR2_BLUE_COLOR
Definition: color2.h:156
color2_get_int_pin
uint8_t color2_get_int_pin(color2_t *ctx)
Get int pin function.
COLOR2_YELLOW_COLOR
#define COLOR2_YELLOW_COLOR
Definition: color2.h:153
color2_rgb_t::blue
uint16_t blue
Definition: color2.h:231
color2_hsl_t::lightness
float lightness
Definition: color2.h:243
color2_get_color
uint8_t color2_get_color(color2_hsl_t *hsl)
Functions for detect colors.
color2_hsl_t::saturation
float saturation
Definition: color2.h:242
COLOR2_BLACK_COLOR
#define COLOR2_BLACK_COLOR
Definition: color2.h:159
COLOR2_WHITE_COLOR
#define COLOR2_WHITE_COLOR
Definition: color2.h:158
application_init
void application_init(void)
Definition: main.c:36
COLOR2_MAP_MIKROBUS
#define COLOR2_MAP_MIKROBUS(cfg, mikrobus)
Definition: color2.h:63
color2_t
Click ctx object definition.
Definition: color2.h:193
color2_read_rgb
err_t color2_read_rgb(color2_t *ctx, color2_rgb_t *rgb)
Function read rgb data.
color2_read_status
err_t color2_read_status(color2_t *ctx, uint8_t *status)
Function read status registe value.
color2_default_cfg
err_t color2_default_cfg(color2_t *ctx)
Click Default Configuration function.
color2_init
err_t color2_init(color2_t *ctx, color2_cfg_t *cfg)
Initialization function.
COLOR2_CYAN_COLOR
#define COLOR2_CYAN_COLOR
Definition: color2.h:155