TOP Contributors

  1. MIKROE (2762 codes)
  2. Alcides Ramos (374 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (118 codes)
  5. Bugz Bensce (91 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 (139271 times)
  2. FAT32 Library (71755 times)
  3. Network Ethernet Library (57128 times)
  4. USB Device Library (47432 times)
  5. Network WiFi Library (43093 times)
  6. FT800 Library (42409 times)
  7. GSM click (29835 times)
  8. mikroSDK (28104 times)
  9. PID Library (26886 times)
  10. microSD click (26198 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-10-31

Package Version: 2.1.0.13

mikroSDK Library: 2.0.0.0

Category: Optical

Downloaded: 182 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

RMS to DC Click

0

RMS to DC Click is a Click board™ that is used to convert the RMS of the input signal into a DC voltage, with a value directly readable over the I2C interface.

[Learn More]

Hydro Probe Click

0

Hydro Probe Click is a capacitive soil moisture sensor based on capacitive changes that are used to detect the volumetric water content in the soil. Water detection is achieved by using function oscillator MIC1557 and ADC converter MCP3221 from Microchip, which allow you to convert moisture presents to the digital value. Compared to resistant soil moisture sensors, its capacitive style reduces electrode erosion making it corrosion resistant and a better choice for applications such as soil moisture detection and automatic plant watering.

[Learn More]

Haptic 4 Click

0

Haptic 4 Click is a compact add-on board that enables precise haptic feedback in various electronic projects. This board features the DA7280, a haptic driver designed to drive linear resonant actuator (LRA) and eccentric rotating mass (ERM) actuators from Renesas. The DA7280 boasts a differential output drive and continuous motion sensing for calibration-free operation, coupled with wide-band support to leverage the capabilities of modern LRAs. It supports six independent haptic sequences activated directly via mikroBUS™ pins or externally through I2C or PWM signals, offering extensive flexibility for haptic configuration. Ideal for enhancing user experience in wearables, electronic peripherals, automotive interfaces, industrial controls, and AR/VR controllers, this Click board™ opens new possibilities for interactive and tactile-responsive technology.

[Learn More]