tamper2 2.0.0.0
Main Page

Tamper 2 click

Tamper 2 click contains a levered D2HW-A221D switch by Omron, which outputs signal in both positions - pressed and released.

click Product page


Click library

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

Software Support

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

Standard key functions :

  • Config Object Initialization function.

    ‍void tamper2_cfg_setup ( tamper2_cfg_t *cfg );

    - Initialization function.

    ‍TAMPER2_RETVAL tamper2_init ( tamper2_t *ctx, tamper2_cfg_t *cfg );

Example key functions :

  • Switch ON detect

    ‍uint8_t tamper2_get_on_state ( tamper2_t *ctx );

    - Switch OFF detect

    ‍uint8_t tamper2_get_off_state ( tamper2_t *ctx );

    Examples Description

‍This application sets switch on ON or OFF.

The demo application is composed of two sections :

Application Init

‍Sends HAL pointers

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.
TAMPER2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
tamper2_init( &tamper2, &cfg );
}
#define TAMPER2_MAP_MIKROBUS(cfg, mikrobus)
Definition tamper2.h:65
TAMPER2_RETVAL tamper2_init(tamper2_t *ctx, tamper2_cfg_t *cfg)
Initialization function.
void tamper2_cfg_setup(tamper2_cfg_t *cfg)
Config Object Initialization function.
void application_init(void)
Definition main.c:32
Click configuration structure definition.
Definition tamper2.h:103

Application Task

‍Detects whether the state of switch on Tamper 2 click is ON or OFF.

{
uint8_t on_state;
uint8_t off_state;
on_state = tamper2_get_on_state( &tamper2 );
off_state = tamper2_get_off_state( &tamper2 );
if ( on_state == 1 )
{
log_printf( &logger, "Tamper 2 click is in ON state.\r\n" );
}
if ( off_state == 1 )
{
log_printf( &logger, "Tamper 2 click is in OFF state.\r\n" );
}
Delay_ms ( 200 );
}
uint8_t tamper2_get_off_state(tamper2_t *ctx)
Switch OFF detect.
uint8_t tamper2_get_on_state(tamper2_t *ctx)
Switch ON detect.
void application_task()
Definition main.c:57

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

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.