buttonalarm  2.0.0.0
Main Page

Button ALARM click

Button ALARM Click is a very interesting interactive gadget on a Click boardâ„¢. It is an integrated capacitive touch sensor display in the form of a button. By utilizing an advanced capacitive touch sensing technology, the CTHS15CIC05ALARM sensor can successfully replace the traditional mechanical button, allowing very simplified yet reliable user interfaces to be developed. Besides the touch detection, this sensor also features a green power symbol icon with backlight, which makes the Click boardâ„¢ very useful for building various stylized and visually appealing interfaces.

click Product page


Click library

  • Author : Nikola Peric
  • Date : Feb 2022.
  • Type : GPIO type

Software Support

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

Standard key functions :

Example key functions :

Example Description

This example showcases how to initialize and use the whole family of Button clicks. One library is used for every single one of them. They are simple touch detectors that send a pressed/released signal and receive a PWM output which controls the backlight on the button.

The demo application is composed of two sections :

Application Init

This function initializes and configures the logger and click modules.

void application_init ( void )
{
log_cfg_t log_cfg;
buttonalarm_cfg_t buttonalarm_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
buttonalarm_cfg_setup( &buttonalarm_cfg );
BUTTONALARM_MAP_MIKROBUS( buttonalarm_cfg, MIKROBUS_1 );
err_t init_flag = buttonalarm_init( &buttonalarm, &buttonalarm_cfg );
if ( PWM_ERROR == init_flag )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
Delay_ms( 500 );
buttonalarm_set_duty_cycle ( &buttonalarm, 0.1 );
buttonalarm_pwm_start( &buttonalarm );
log_info( &logger, " Application Task " );
}

Application Task

This example first increases the backlight on the button and then decreases the intensity of the backlight. When the button is touched,
reports the event in the console using UART communication.

void application_task ( void )
{
static float duty_cycle;
static uint8_t button_state;
static uint8_t button_state_old;
button_state = buttonalarm_get_button_state( &buttonalarm );
if ( button_state && ( button_state != button_state_old ) )
{
log_printf( &logger, " <-- Button pressed --> \r\n" );
for ( uint8_t n_cnt = 1; n_cnt <= 100; n_cnt++ )
{
duty_cycle = ( float ) n_cnt ;
duty_cycle /= 100;
buttonalarm_set_duty_cycle( &buttonalarm, duty_cycle );
Delay_ms( 10 );
}
button_state_old = button_state;
}
else if ( !button_state && ( button_state != button_state_old ) )
{
for ( uint8_t n_cnt = 100; n_cnt > 0; n_cnt-- )
{
duty_cycle = ( float ) n_cnt ;
duty_cycle /= 100;
buttonalarm_set_duty_cycle( &buttonalarm, duty_cycle );
Delay_ms( 10 );
}
button_state_old = button_state;
}
}

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

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.


buttonalarm_init
err_t buttonalarm_init(buttonalarm_t *ctx, buttonalarm_cfg_t *cfg)
Button Alarm initialization function.
buttonalarm_pwm_stop
err_t buttonalarm_pwm_stop(buttonalarm_t *ctx)
Button Alarm stop PWM module.
buttonalarm_set_duty_cycle
err_t buttonalarm_set_duty_cycle(buttonalarm_t *ctx, float duty_cycle)
Button Alarm sets PWM duty cycle.
buttonalarm_cfg_t
Button Alarm Click configuration object.
Definition: buttonalarm.h:110
application_task
void application_task(void)
Definition: main.c:68
buttonalarm_cfg_setup
void buttonalarm_cfg_setup(buttonalarm_cfg_t *cfg)
Button Alarm configuration object setup function.
application_init
void application_init(void)
Definition: main.c:30
buttonalarm_get_button_state
uint8_t buttonalarm_get_button_state(buttonalarm_t *ctx)
Button Alarm get button state function.
buttonalarm_t
Button Alarm Click driver selector.
Definition: buttonalarm.h:94
buttonalarm_pwm_start
err_t buttonalarm_pwm_start(buttonalarm_t *ctx)
Button Alarm start PWM module.
BUTTONALARM_MAP_MIKROBUS
#define BUTTONALARM_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: buttonalarm.h:77