2x2rgb 2.2.0
Loading...
Searching...
No Matches
2x2rgb


2x2 RGB Click

2x2 RGB 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 : Sep 2023.
  • Type : I2C type

Software Support

Example Description

This example demonstrates the use of the 2x2 RGB Click board™ by controlling the color of the LEDs [1-4].

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.2x2RGB

Example Key Functions

  • c2x2rgb_cfg_setup Config Object Initialization function.
    void c2x2rgb_cfg_setup(c2x2rgb_cfg_t *cfg)
    2x2 RGB configuration object setup function.
    2x2 RGB Click configuration object.
    Definition c2x2rgb.h:240
  • c2x2rgb_init Initialization function.
    err_t c2x2rgb_init ( c2x2rgb_t *ctx, c2x2rgb_cfg_t *cfg );
    err_t c2x2rgb_init(c2x2rgb_t *ctx, c2x2rgb_cfg_t *cfg)
    2x2 RGB initialization function.
    2x2 RGB Click context object.
    Definition c2x2rgb.h:225
  • c2x2rgb_default_cfg Click Default Configuration function.
    err_t c2x2rgb_default_cfg(c2x2rgb_t *ctx)
    2x2 RGB default configuration function.
  • c2x2rgb_set_rgb_led 2x2 RGB set RGB LED function.
    err_t c2x2rgb_set_rgb_led ( c2x2rgb_t *ctx, uint8_t led_num, uint16_t ired, uint16_t igrn, uint16_t iblu );
    err_t c2x2rgb_set_rgb_led(c2x2rgb_t *ctx, uint8_t led_num, uint16_t ired, uint16_t igrn, uint16_t iblu)
    2x2 RGB set RGB LED function.
  • c2x2rgb_set_control 2x2 RGB set control function.
    err_t c2x2rgb_set_control ( c2x2rgb_t *ctx, uint8_t en_mode, uint8_t be_en,
    uint8_t ce_temp, uint8_t fade_rate );
    err_t c2x2rgb_set_control(c2x2rgb_t *ctx, uint8_t en_mode, uint8_t be_en, uint8_t ce_temp, uint8_t fade_rate)
    2x2 RGB set control function.

Application Init

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

void application_init ( void )
{
log_cfg_t log_cfg;
c2x2rgb_cfg_t c2x2rgb_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
c2x2rgb_cfg_setup( &c2x2rgb_cfg );
C2X2RGB_MAP_MIKROBUS( c2x2rgb_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == c2x2rgb_init( &c2x2rgb, &c2x2rgb_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( C2X2RGB_ERROR == c2x2rgb_default_cfg ( &c2x2rgb ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
log_printf( &logger, "----------------" );
Delay_ms ( 100 );
}
@ C2X2RGB_ERROR
Definition c2x2rgb.h:278
#define C2X2RGB_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition c2x2rgb.h:213
void application_init(void)
Definition main.c:33

Application Task

This simple example shows all LEDs in different colors. These LEDs actually consist of three single-colored LEDs (Red, Green and 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\nRED: " );
for ( uint8_t led_pos = C2X2RGB_SET_LD1; led_pos <= C2X2RGB_SET_LD4; led_pos++ )
{
if ( C2X2RGB_OK == c2x2rgb_set_rgb_led( &c2x2rgb, led_pos, DEMO_LED_CURRENT,
{
log_printf( &logger, "LD%d ", ( uint16_t ) led_pos );
}
Delay_ms ( 200 );
}
log_printf( &logger, "\r\nGREEN: " );
for ( uint8_t led_pos = C2X2RGB_SET_LD1; led_pos <= C2X2RGB_SET_LD4; led_pos++ )
{
{
log_printf( &logger, "LD%d ", ( uint16_t ) led_pos );
}
Delay_ms ( 200 );
}
log_printf( &logger, "\r\nBLUE: " );
for ( uint8_t led_pos = C2X2RGB_SET_LD1; led_pos <= C2X2RGB_SET_LD4; led_pos++ )
{
{
log_printf( &logger, "LD%d ", ( uint16_t ) led_pos );
}
Delay_ms ( 200 );
}
log_printf( &logger, "\r\nWHITE: " );
for ( uint8_t led_pos = C2X2RGB_SET_LD1; led_pos <= C2X2RGB_SET_LD4; led_pos++ )
{
if ( C2X2RGB_OK == c2x2rgb_set_rgb_led( &c2x2rgb, led_pos, DEMO_LED_CURRENT,
{
log_printf( &logger, "LD%d ", ( uint16_t ) led_pos );
}
Delay_ms ( 200 );
}
log_printf( &logger, "\r\n----------------" );
}
@ C2X2RGB_OK
Definition c2x2rgb.h:277
#define C2X2RGB_SET_LD1
2x2 RGB LED selection data values.
Definition c2x2rgb.h:112
#define C2X2RGB_SET_LD4
Definition c2x2rgb.h:115
#define C2X2RGB_LED_CURRENT_OFF
2x2 RGB LED current setting data values.
Definition c2x2rgb.h:139
void application_task(void)
Definition main.c:71
#define DEMO_LED_CURRENT
Definition main.c:28

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.