color3 2.2.0
color3


Color 3 Click

Color 3 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

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

Software Support

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

Example Libraries

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

Example Key Functions

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

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.