c1x4rgb  2.1.0.0
Main Page

1x4 RGB click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Nenad Filipovic
  • Date : Feb 2024.
  • Type : I2C type

Software Support

We provide a library for the 1x4 RGB 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 from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for 1x4 RGB Click driver.

Standard key functions :

Example key functions :

  • c1x4rgb_set_rgb_color This function sets the desired values of RGB colors for the selected LED by using the I2C serial interface.
    err_t c1x4rgb_set_rgb_color ( c1x4rgb_t *ctx, uint8_t led_pos, uint8_t red, uint8_t green, uint8_t blue );
  • c1x4rgb_enable_leds This function turns on the desired LEDs by using the I2C serial interface.
    err_t c1x4rgb_enable_leds ( c1x4rgb_t *ctx, uint16_t led_bitmask );
  • c1x4rgb_set_tmc_mode This function configures the desired LED drive mode as TCM 1/2/3/4 scans using the I2C serial interface.
    err_t c1x4rgb_set_tmc_mode ( c1x4rgb_t *ctx, uint8_t dev_cfg, uint8_t mode );

Example Description

This example demonstrates the use of the 1x4 RGB Click board by controlling the color of the LEDs [LD1-LD4].

The demo application is composed of two sections :

Application Init

Initialization of I2C module and log UART. After driver initialization, the app executes a default configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
c1x4rgb_cfg_t c1x4rgb_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
c1x4rgb_cfg_setup( &c1x4rgb_cfg );
C1X4RGB_MAP_MIKROBUS( c1x4rgb_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == c1x4rgb_init( &c1x4rgb, &c1x4rgb_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( C1X4RGB_ERROR == c1x4rgb_default_cfg ( &c1x4rgb ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
Delay_ms( 1000 );
}

Application Task

The demo example shows the color change of four RGB LEDs, starting with red color, through green and blue, and ending with white. These LEDs actually consist of three single-colored LEDs (Red-Green-Blue) in a single package. Various colors can be reproduced by mixing the intensity of each LED.

void application_task ( void )
{
log_printf( &logger, "\r\n\n RED: " );
for ( uint8_t led_pos = C1X4RGB_LED_POS_LD1; led_pos <= C1X4RGB_LED_POS_LD4; led_pos++ )
{
if ( C1X4RGB_OK == c1x4rgb_set_rgb_color( &c1x4rgb, led_pos, DEMO_COLOR_INT_100,
{
log_printf( &logger, " LD%d ", ( uint16_t ) led_pos );
Delay_ms( 100 );
}
}
log_printf( &logger, "\r\n GREEN: " );
for ( uint8_t led_pos = C1X4RGB_LED_POS_LD1; led_pos <= C1X4RGB_LED_POS_LD4; led_pos++ )
{
if ( C1X4RGB_OK == c1x4rgb_set_rgb_color( &c1x4rgb, led_pos, DEMO_COLOR_INT_0,
{
log_printf( &logger, " LD%d ", ( uint16_t ) led_pos );
Delay_ms( 100 );
}
}
log_printf( &logger, "\r\n BLUE: " );
for ( uint8_t led_pos = C1X4RGB_LED_POS_LD1; led_pos <= C1X4RGB_LED_POS_LD4; led_pos++ )
{
if ( C1X4RGB_OK == c1x4rgb_set_rgb_color( &c1x4rgb, led_pos, DEMO_COLOR_INT_0,
{
log_printf( &logger, " LD%d ", ( uint16_t ) led_pos );
Delay_ms( 100 );
}
}
log_printf( &logger, "\r\n WHITE:" );
for ( uint8_t led_pos = C1X4RGB_LED_POS_LD1; led_pos <= C1X4RGB_LED_POS_LD4; led_pos++ )
{
if ( C1X4RGB_OK == c1x4rgb_set_rgb_color( &c1x4rgb, led_pos, DEMO_COLOR_INT_100,
{
log_printf( &logger, " LD%d ", ( uint16_t ) led_pos );
Delay_ms( 100 );
}
}
}

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.1x4RGB

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. UART terminal is available in all MikroElektronika compilers.


c1x4rgb_default_cfg
err_t c1x4rgb_default_cfg(c1x4rgb_t *ctx)
1x4 RGB default configuration function.
DEMO_COLOR_INT_100
#define DEMO_COLOR_INT_100
Definition: main.c:35
C1X4RGB_LED_POS_LD4
#define C1X4RGB_LED_POS_LD4
Definition: c1x4rgb.h:284
c1x4rgb_set_tmc_mode
err_t c1x4rgb_set_tmc_mode(c1x4rgb_t *ctx, uint8_t dev_cfg, uint8_t mode)
1x4 RGB set TCM mode function.
c1x4rgb_enable_leds
err_t c1x4rgb_enable_leds(c1x4rgb_t *ctx, uint16_t led_bitmask)
1x4 RGB enable LEDs function.
c1x4rgb_cfg_t
1x4 RGB Click configuration object.
Definition: c1x4rgb.h:353
DEMO_COLOR_INT_0
#define DEMO_COLOR_INT_0
Definition: main.c:34
application_task
void application_task(void)
Definition: main.c:74
C1X4RGB_LED_POS_LD1
#define C1X4RGB_LED_POS_LD1
1x4 RGB LEDs position selection.
Definition: c1x4rgb.h:281
C1X4RGB_MAP_MIKROBUS
#define C1X4RGB_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: c1x4rgb.h:323
c1x4rgb_set_rgb_color
err_t c1x4rgb_set_rgb_color(c1x4rgb_t *ctx, uint8_t led_pos, uint8_t red, uint8_t green, uint8_t blue)
1x4 RGB set colors function.
C1X4RGB_OK
@ C1X4RGB_OK
Definition: c1x4rgb.h:396
c1x4rgb_init
err_t c1x4rgb_init(c1x4rgb_t *ctx, c1x4rgb_cfg_t *cfg)
1x4 RGB initialization function.
application_init
void application_init(void)
Definition: main.c:37
c1x4rgb_t
1x4 RGB Click context object.
Definition: c1x4rgb.h:336
C1X4RGB_ERROR
@ C1X4RGB_ERROR
Definition: c1x4rgb.h:397
c1x4rgb_cfg_setup
void c1x4rgb_cfg_setup(c1x4rgb_cfg_t *cfg)
1x4 RGB configuration object setup function.