Joystick 2 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 : Katarina Perendic
- Date : okt 2019.
- Type : I2C type
The demo application shows reading the joistick position ..
- MikroSDK.Board
- MikroSDK.Log
- Click.Joystick2
joystick2_cfg_setup
Config Object Initialization function.
void joystick2_cfg_setup ( joystick2_cfg_t *cfg );
joystick2_init
Initialization function.
err_t joystick2_init ( joystick2_t *ctx, joystick2_cfg_t *cfg );
joystick2_default_cfg
Click Default Configuration function.
void joystick2_default_cfg ( joystick2_t *ctx );
joystick2_set_cfg_register
Functions for configuration joystick.
void joystick2_set_cfg_register ( joystick2_t *ctx, uint8_t cfg_data );
joystick2_get_position
Functions for get Joystick position.
uint8_t joystick2_get_position ( joystick2_t *ctx );
joystick2_get_interrupt_state
Functions for read interrupt state.
uint8_t joystick2_get_interrupt_state ( joystick2_t *ctx );
Configuring Clicks and log objects. Reset device and settings the Click in the default configuration.
void application_init ( void )
{
log_cfg_t log_cfg;
joystick2_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.
joystick2_cfg_setup( &cfg );
JOYSTICK2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
joystick2_init( &joystick2, &cfg );
joystick2_reset( &joystick2 );
joystick2_default_cfg( &joystick2 );
log_info( &logger, "---- JOYSTICK START ----" );
}
It reads the position of the joystick, if it detects that the joystick has moved from the zero position, it prints a message about the current position.
void application_task ( void )
{
uint8_t joystick_pos;
// Task implementation.
joystick_pos = joystick2_get_position( &joystick2 );
switch ( joystick_pos )
{
case JOYSTICK2_BUTTON_ACTIVE:
{
log_info( &logger, "--- Button is pressed!!! ---" );
Delay_ms ( 300 );
break;
}
case JOYSTICK2_POSITION_RIGHT:
{
log_info( &logger, "--- Joystick position [RIGHT] ---" );
Delay_ms ( 300 );
break;
}
case JOYSTICK2_POSITION_LEFT:
{
log_info( &logger, "--- Joystick position [LEFT] ---" );
Delay_ms ( 300 );
break;
}
case JOYSTICK2_POSITION_UP:
{
log_info( &logger, "--- Joystick position [UP] ---" );
Delay_ms ( 300 );
break;
}
case JOYSTICK2_POSITION_DOWN:
{
log_info( &logger, "--- Joystick position [DOWN] ---" );
Delay_ms ( 300 );
break;
}
}
}
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.