thumbstick  2.0.0.0
Main Page

Thumbstiick click

Thumbstick click is a high precision input device. It features a dual axis, spring return, pushbutton enabled joystick (similar to the ones used on joypads on popular gaming consoles), and a MCP3204 12-bit A/D converter.

It features a dual axis, spring return, pushbutton enabled joystick, and a MCP3204 12-bit A/D converter.

click Product page


Click library

  • Author : Katarina Perendic
  • Date : okt 2019.
  • Type : SPI type

Software Support

We provide a library for the Thumbstick 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 form compilers IDE(recommended way), or downloaded from our LibStock, or found on mikroE github account.

Library Description

This library contains API for Thumbstick Click driver.

Standard key functions :

Example key functions :

Examples Description

The demo application shows reading the thumbstick position ..

The demo application is composed of two sections :

Application Init

Configuring clicks and log objects.

void application_init ( void )
{
log_cfg_t log_cfg;
// Logger initialization.
log_cfg.level = LOG_LEVEL_DEBUG;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
// Click initialization.
THUMBSTICK_MAP_MIKROBUS( cfg, MIKROBUS_1 );
thumbstick_init( &thumbstick, &cfg );
}

Application Task

It reads the position of the thumbstick,

  • if it detects that the thumbstick has moved from the zero position, it prints a message about the current position.
  • It also checks the status of the switch button.
void application_task ( void )
{
uint8_t pos;
uint8_t button_state;
pos = thumbstick_get_position( &thumbstick );
button_state = thumbstick_button_state( &thumbstick );
if ( button_state == THUMBSTICK_PRESS_BUTTON )
{
log_printf( &logger, ">> Button is pressted \r\n" );
}
switch ( pos )
{
{
log_printf( &logger, ">> Position: [ TOP ] \r\n" );
break;
}
{
log_printf( &logger, ">> Position: [ RIGHT ] \r\n" );
break;
}
{
log_printf( &logger, ">> Position: [ BOTTOM ] \r\n" );
break;
}
{
log_printf( &logger, ">> Position: [ LEFT ] \r\n" );
break;
}
}
Delay_ms( 30 );
}

The full application code, and ready to use projects can be installed directly form compilers IDE(recommneded) or found on LibStock page or mikroE GitHub accaunt.

Other mikroE Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.Thumbstick

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. The terminal available in all Mikroelektronika compilers, or any other terminal application of your choice, can be used to read the message.


THUMBSTICK_CHANNEL_LEFT
#define THUMBSTICK_CHANNEL_LEFT
Definition: thumbstick.h:81
THUMBSTICK_PRESS_BUTTON
#define THUMBSTICK_PRESS_BUTTON
Definition: thumbstick.h:90
thumbstick_get_position
uint8_t thumbstick_get_position(thumbstick_t *ctx)
Get thumbstick position function.
THUMBSTICK_POSITION_RIGHT
#define THUMBSTICK_POSITION_RIGHT
Definition: thumbstick.h:79
application_task
void application_task(void)
Definition: main.c:54
thumbstick_cfg_t
Click configuration structure definition.
Definition: thumbstick.h:118
application_init
void application_init(void)
Definition: main.c:35
thumbstick_cfg_setup
void thumbstick_cfg_setup(thumbstick_cfg_t *cfg)
Config Object Initialization function.
THUMBSTICK_MAP_MIKROBUS
#define THUMBSTICK_MAP_MIKROBUS(cfg, mikrobus)
Definition: thumbstick.h:52
thumbstick_button_state
uint8_t thumbstick_button_state(thumbstick_t *ctx)
Get state of thumbstick button function.
THUMBSTICK_POSITION_TOP
#define THUMBSTICK_POSITION_TOP
Definition: thumbstick.h:78
THUMBSTICK_CHANNEL_BOTTOM
#define THUMBSTICK_CHANNEL_BOTTOM
Definition: thumbstick.h:80
thumbstick_init
THUMBSTICK_RETVAL thumbstick_init(thumbstick_t *ctx, thumbstick_cfg_t *cfg)
Initialization function.