joystick4  2.1.0.0
Main Page

Joystick 4 click

Joystick 4 Click is a compact add-on board that provides precise and reliable input control for various interactive projects. This board features the 2434804-1, a 5-position tactile switch from the ALCOSWITCH series by TE Connectivity. The switch features an extended top actuator for precise input detection, a stainless steel contact base, and silver contact plating, ensuring durability and corrosion resistance with a lifespan of 100,000 cycles. With a low-profile design, it handles a contact current rating of 50mA.

click Product page


Click library

  • Author : Stefan Filipovic
  • Date : Jun 2024.
  • Type : I2C type

Software Support

We provide a library for the Joystick 4 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 Joystick 4 Click driver.

Standard key functions :

Example key functions :

  • joystick4_get_int_pin This function returns the INT pin logic state.
  • joystick4_get_pins This function reads all input pins logic state.
    err_t joystick4_get_pins ( joystick4_t *ctx, uint8_t *pin_mask );
  • joystick4_get_position This function returns the joystick position flag extracted from the input pins state mask.
    uint8_t joystick4_get_position ( uint8_t pin_mask );

Example Description

This example demonstrates the use of the Joystick 4 click board by reading and displaying the joystick position.

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;
joystick4_cfg_t joystick4_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
joystick4_cfg_setup( &joystick4_cfg );
JOYSTICK4_MAP_MIKROBUS( joystick4_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == joystick4_init( &joystick4, &joystick4_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( JOYSTICK4_ERROR == joystick4_default_cfg ( &joystick4 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
{
log_printf ( &logger, " Joystick position: IDLE\r\n\n" );
}
}

Application Task

Waits for the input change interrupt, reads the input pins mask, extracts the joystick position from those readings, and displays it on the USB UART.

void application_task ( void )
{
uint8_t pin_mask = 0;
{
if ( JOYSTICK4_OK == joystick4_get_pins ( &joystick4, &pin_mask ) )
{
log_printf ( &logger, " Joystick position: " );
switch ( joystick4_get_position ( pin_mask ) )
{
{
log_printf ( &logger, "IDLE" );
break;
}
{
log_printf ( &logger, "CENTER" );
break;
}
{
log_printf ( &logger, "CENTER-UP" );
break;
}
{
log_printf ( &logger, "CENTER-RIGHT" );
break;
}
{
log_printf ( &logger, "CENTER-DOWN" );
break;
}
{
log_printf ( &logger, "CENTER-LEFT" );
break;
}
{
log_printf ( &logger, "UP" );
break;
}
{
log_printf ( &logger, "UPPER-RIGHT" );
break;
}
{
log_printf ( &logger, "RIGHT" );
break;
}
{
log_printf ( &logger, "LOWER-RIGHT" );
break;
}
{
log_printf ( &logger, "DOWN" );
break;
}
{
log_printf ( &logger, "LOWER-LEFT" );
break;
}
{
log_printf ( &logger, "LEFT" );
break;
}
{
log_printf ( &logger, "UPPER-LEFT" );
break;
}
default:
{
log_printf ( &logger, "UNKNOWN" );
break;
}
}
log_printf ( &logger, "\r\n\n" );
}
}
}

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.Joystick4

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.


joystick4_t
Joystick 4 Click context object.
Definition: joystick4.h:170
JOYSTICK4_POSITION_LOWER_LEFT
#define JOYSTICK4_POSITION_LOWER_LEFT
Definition: joystick4.h:128
JOYSTICK4_POSITION_CENTER_LEFT
#define JOYSTICK4_POSITION_CENTER_LEFT
Definition: joystick4.h:122
joystick4_get_int_pin
uint8_t joystick4_get_int_pin(joystick4_t *ctx)
Joystick 4 get INT pin function.
joystick4_cfg_setup
void joystick4_cfg_setup(joystick4_cfg_t *cfg)
Joystick 4 configuration object setup function.
joystick4_get_position
uint8_t joystick4_get_position(uint8_t pin_mask)
Joystick 4 get position function.
JOYSTICK4_MAP_MIKROBUS
#define JOYSTICK4_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: joystick4.h:156
JOYSTICK4_POSITION_IDLE
#define JOYSTICK4_POSITION_IDLE
Joystick 4 position values.
Definition: joystick4.h:117
joystick4_cfg_t
Joystick 4 Click configuration object.
Definition: joystick4.h:190
JOYSTICK4_OK
@ JOYSTICK4_OK
Definition: joystick4.h:208
application_task
void application_task(void)
Definition: main.c:70
JOYSTICK4_POSITION_RIGHT
#define JOYSTICK4_POSITION_RIGHT
Definition: joystick4.h:125
JOYSTICK4_ERROR
@ JOYSTICK4_ERROR
Definition: joystick4.h:209
joystick4_get_pins
err_t joystick4_get_pins(joystick4_t *ctx, uint8_t *pin_mask)
Joystick 4 get pins function.
JOYSTICK4_PIN_STATE_LOW
#define JOYSTICK4_PIN_STATE_LOW
Joystick 4 pin logic state setting.
Definition: joystick4.h:110
JOYSTICK4_POSITION_CENTER_DOWN
#define JOYSTICK4_POSITION_CENTER_DOWN
Definition: joystick4.h:121
JOYSTICK4_POSITION_UPPER_LEFT
#define JOYSTICK4_POSITION_UPPER_LEFT
Definition: joystick4.h:130
JOYSTICK4_POSITION_DOWN
#define JOYSTICK4_POSITION_DOWN
Definition: joystick4.h:127
JOYSTICK4_POSITION_UP
#define JOYSTICK4_POSITION_UP
Definition: joystick4.h:123
JOYSTICK4_PIN_STATE_HIGH
#define JOYSTICK4_PIN_STATE_HIGH
Definition: joystick4.h:111
JOYSTICK4_POSITION_CENTER_RIGHT
#define JOYSTICK4_POSITION_CENTER_RIGHT
Definition: joystick4.h:120
JOYSTICK4_POSITION_LOWER_RIGHT
#define JOYSTICK4_POSITION_LOWER_RIGHT
Definition: joystick4.h:126
JOYSTICK4_POSITION_UPPER_RIGHT
#define JOYSTICK4_POSITION_UPPER_RIGHT
Definition: joystick4.h:124
JOYSTICK4_POSITION_LEFT
#define JOYSTICK4_POSITION_LEFT
Definition: joystick4.h:129
JOYSTICK4_POSITION_CENTER_UP
#define JOYSTICK4_POSITION_CENTER_UP
Definition: joystick4.h:119
application_init
void application_init(void)
Definition: main.c:29
JOYSTICK4_POSITION_CENTER
#define JOYSTICK4_POSITION_CENTER
Definition: joystick4.h:118
joystick4_default_cfg
err_t joystick4_default_cfg(joystick4_t *ctx)
Joystick 4 default configuration function.
joystick4_init
err_t joystick4_init(joystick4_t *ctx, joystick4_cfg_t *cfg)
Joystick 4 initialization function.