keylock2 2.0.0.0
Main Page

Key Lock 2 click

Keylock 2 Click carries antistatic process sealed keylock mechanism that has three positions.

click Product page


Click library

  • Author : MikroE Team
  • Date : Nov 2019.
  • Type : GPIO type

Software Support

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

Standard key functions :

  • Config Object Initialization function.

    ‍void keylock2_cfg_setup ( keylock2_cfg_t *cfg );

    - Initialization function.

    ‍KEYLOCK2_RETVAL keylock2_init ( keylock2_t *ctx, keylock2_cfg_t *cfg );

  • Click Default Configuration function.

    ‍void keylock2_default_cfg ( keylock2_t *ctx );

Example key functions :

  • This function gets states of pins out1, out2 and out3 on Key Lock 2 click.

    ‍uint8_t keylock2_get_pin_state ( keylock2_t *ctx, uint8_t pin );

    - This function gets Position (First, Second, Third) of pins out1, out2 and out3 on Key Lock 2 click.

    ‍uint8_t keylock2_get_position ( keylock2_t *ctx )

Examples Description

‍Keylock 2 Click carries antistatic process sealed keylock mechanism that has three positions.

The demo application is composed of two sections :

Application Init

‍Initialization driver init.

void application_init ( void )
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info(&logger, "---- Application Init ----");
// Click initialization.
KEYLOCK2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
keylock2_init( &keylock2, &cfg );
}
#define KEYLOCK2_MAP_MIKROBUS(cfg, mikrobus)
Definition keylock2.h:64
KEYLOCK2_RETVAL keylock2_init(keylock2_t *ctx, keylock2_cfg_t *cfg)
Initialization function.
void keylock2_cfg_setup(keylock2_cfg_t *cfg)
Config Object Initialization function.
void application_init(void)
Definition main.c:36
Click configuration structure definition.
Definition keylock2.h:122

Application Task

‍Checks the current key position and logs the current position on the USB UART.

void application_task ( void )
{
{
{
log_printf( &logger, " -- FIRST position -- \r\n " );
}
{
log_printf( &logger, " -- SECOND position -- \r\n " );
}
else
{
log_printf( &logger, " -- THIRD position -- \r\n " );
}
}
Delay_ms ( 500 );
}
#define KEYLOCK2_POSITION_1
Definition keylock2.h:93
#define KEYLOCK2_POSITION_2
Definition keylock2.h:94
uint8_t keylock2_get_position(keylock2_t *ctx)
Get Pin State.
uint8_t key_position
Definition main.c:32
void application_task(void)
Definition main.c:61
uint8_t old_position
Definition main.c:31

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

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.