BarGraph 5 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.
- Author : Stefan Filipovic
- Date : Jun 2024.
- Type : SPI type
This example demonstrates the use of BarGraph 5 Click board by changing the level of all BarGraph output channels.
- MikroSDK.Board
- MikroSDK.Log
- Click.BarGraph5
bargraph5_cfg_setup
Config Object Initialization function.
void bargraph5_cfg_setup ( bargraph5_cfg_t *cfg );
bargraph5_init
Initialization function.
err_t bargraph5_init ( bargraph5_t *ctx, bargraph5_cfg_t *cfg );
bargraph5_default_cfg
Click Default Configuration function.
err_t bargraph5_default_cfg ( bargraph5_t *ctx );
bargraph5_set_bar_level
This function sets the level of a selected BarGraph channel at the selected brightness.
err_t bargraph5_set_bar_level ( bargraph5_t *ctx, bargraph5_bar_sel_t bar_num, bargraph5_level_t level, uint16_t brightness );
bargraph5_output_enable
This function enables the BarGraph LEDs output by setting the BLANK pin to low logic state.
void bargraph5_output_enable ( bargraph5_t *ctx );
bargraph5_output_disable
This function disables the BarGraph LEDs output by setting the BLANK pin to high logic state.
void bargraph5_output_disable ( bargraph5_t *ctx );
Initializes the driver and performs the Click default configuration.
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
bargraph5_cfg_t bargraph5_cfg; /**< Click config object. */
/**
* 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.
bargraph5_cfg_setup( &bargraph5_cfg );
BARGRAPH5_MAP_MIKROBUS( bargraph5_cfg, MIKROBUS_1 );
if ( SPI_MASTER_ERROR == bargraph5_init( &bargraph5, &bargraph5_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( BARGRAPH5_ERROR == bargraph5_default_cfg ( &bargraph5 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
Changes the level of all BarGraph channels once per second. The channels level is displayed on the USB UART.
void application_task ( void )
{
for ( bargraph5_level_t cnt = BARGRAPH5_LEVEL_0; cnt <= BARGRAPH5_LEVEL_4; cnt++ )
{
bargraph5_set_bar_level ( &bargraph5, BARGRAPH5_BAR_0, cnt, BARGRAPH5_BRIGHTNESS_DEFAULT );
bargraph5_set_bar_level ( &bargraph5, BARGRAPH5_BAR_1, BARGRAPH5_LEVEL_4 - cnt, BARGRAPH5_BRIGHTNESS_DEFAULT );
bargraph5_set_bar_level ( &bargraph5, BARGRAPH5_BAR_2, cnt, BARGRAPH5_BRIGHTNESS_DEFAULT );
bargraph5_set_bar_level ( &bargraph5, BARGRAPH5_BAR_3, BARGRAPH5_LEVEL_4 - cnt, BARGRAPH5_BRIGHTNESS_DEFAULT );
bargraph5_set_bar_level ( &bargraph5, BARGRAPH5_BAR_4, cnt, BARGRAPH5_BRIGHTNESS_DEFAULT );
bargraph5_set_bar_level ( &bargraph5, BARGRAPH5_BAR_5, BARGRAPH5_LEVEL_4 - cnt, BARGRAPH5_BRIGHTNESS_DEFAULT );
log_printf( &logger, " Bars 0-2-4 level: %u\r\n", ( uint16_t ) cnt );
log_printf( &logger, " Bars 1-3-5 level: %u\r\n\n", ( uint16_t ) ( BARGRAPH5_LEVEL_4 - cnt ) );
Delay_ms ( 1000 );
}
}
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.
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.