TOP Contributors

  1. MIKROE (2663 codes)
  2. Alcides Ramos (358 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (112 codes)
  5. Chisanga Mumba (90 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (137110 times)
  2. FAT32 Library (70237 times)
  3. Network Ethernet Library (56129 times)
  4. USB Device Library (46434 times)
  5. Network WiFi Library (42080 times)
  6. FT800 Library (41390 times)
  7. GSM click (29118 times)
  8. mikroSDK (26564 times)
  9. PID Library (26503 times)
  10. microSD click (25487 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
mikroSDK Library

Color 3 click

Rating:

0

Author: MIKROE

Last Updated: 2024-04-03

Package Version: 2.1.0.11

mikroSDK Library: 2.0.0.0

Category: Optical

Downloaded: 103 times

Not followed.

License: MIT license  

This application return the color of object.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "Color 3 click" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "Color 3 click" changes.

Do you want to report abuse regarding "Color 3 click".

  • mikroSDK Library 1.0.0.0
  • Comments (0)

mikroSDK Library Blog


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

color3_click.png

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 :

  • color3_cfg_setup Config Object Initialization function.

    void color3_cfg_setup ( color3_cfg_t *cfg ); 
  • color3_init Initialization function.

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

Example key functions :

  • 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 );
  • 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 );
  • color3_get_color This function returns the color name flag from the input HSL color.

    uint8_t color3_get_color ( color3_hsl_t *hsl );

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

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;
    color3_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    //  Click initialization.
    color3_cfg_setup( &cfg );
    COLOR3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    color3_init( &color3, &cfg );
    Delay_ms ( 100 );

    color3_set_default_settings( &color3 );
    Delay_ms ( 1000 );

    log_printf( &logger, "-----------------\r\n" );
    log_printf( &logger, " Color 3  Click  \r\n" );
    log_printf( &logger, "-----------------\r\n" );
}

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 )
{
    color3_channels_t rgbc;
    if ( COLOR3_OK == color3_get_rgbc_data ( &color3, &rgbc ) )
    {
        color3_hsl_t hsl;
        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 ) )
        {
            case COLOR3_RED_COLOR:
            {
                log_printf ( &logger, "RED\r\n" );
                break;
            }
            case COLOR3_YELLOW_COLOR:
            {
                log_printf ( &logger, "YELLOW\r\n" );
                break;
            }
            case COLOR3_GREEN_COLOR:
            {
                log_printf ( &logger, "GREEN\r\n" );
                break;
            }
            case COLOR3_CYAN_COLOR:
            {
                log_printf ( &logger, "CYAN\r\n" );
                break;
            }
            case COLOR3_BLUE_COLOR:
            {
                log_printf ( &logger, "BLUE\r\n" );
                break;
            }
            case COLOR3_MAGENTA_COLOR:
            {
                log_printf ( &logger, "MAGENTA\r\n" );
                break;
            }
            case COLOR3_WHITE_COLOR:
            {
                log_printf ( &logger, "WHITE\r\n" );
                break;
            }
            case COLOR3_BLACK_COLOR:
            {
                log_printf ( &logger, "BLACK\r\n" );
                break;
            }
            default:
            {
                log_printf ( &logger, "UNKNOWN\r\n" );
                break;
            }
        }
    }
    Delay_ms ( 500 );
}  

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.


ALSO FROM THIS AUTHOR

UVA click

0

UVA Click is a compact add-on board used to detect solar UV index. This board features the GUVA-C32SM, an ultraviolet light sensor capable of measuring UV index between 0 to 14 from Genicom Co., Ltd. It contains the GaN-based chip die, amplifiers, ADC, digital control logic, and I2C interface circuit to measure UVA volumes, working in the spectral range of 220-370nm. The GUVA-C32M can acquire the intensity of UVA, respectively, and outputs digital count according to each intensity.

[Learn More]

4D - display click

5

4D - display click is an adapter Click board that offers a mikroBUS interface for controlling 4D Systems gen4 Series intelligent Display Modules. 4D Systems designs and manufactures a wide range of Intelligent Display Modules equipped with powerful graphics processors.

[Learn More]

Thermo 14 click

5

Thermo 14 Click uses the STTS22H digital temperature sensor and thermal watchdog, which can measure temperature measurements between -40°C and +125°C so that the temperature measurement data can be processed by the host MCU. Thermo 14 click provides an accuracy of ±0.5°C in the range from -10°C to 60°C.

[Learn More]