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
- color3_cfg_setup Config Object Initialization function.
void color3_cfg_setup(color3_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition color3.h:305
- color3_init Initialization function.
err_t color3_init(color3_t *ctx, color3_cfg_t *cfg)
Initialization function.
Click ctx object definition.
Definition color3.h:289
- color3_get_rgbc_data This function reads data from 4 channels (Red, Green, Blue, Clear).
err_t color3_get_rgbc_data(color3_t *ctx, color3_channels_t *channels)
Color 3 get rgbc data function.
Color 3 RGBC channels data object.
Definition color3.h:324
- color3_rgbc_to_hsl This function converts RGBC (red, green, blue, clear) to HSL (hue, saturation, lightness) color value.
void color3_rgbc_to_hsl(color3_t *ctx, color3_channels_t *rgbc, color3_hsl_t *hsl)
Color 3 rgbc to hsl function.
Color 3 HSL color data object.
Definition color3.h:337
- color3_get_color This function returns the color name flag from the input HSL color.
uint8_t color3_get_color(color3_hsl_t *hsl)
Color 3 get color function.
Application Init
Initializes the driver and performs the Click default configuration.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
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.
{
{
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: " );
{
{
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.