buttonpower  2.0.0.0
Main Page

Button Power click

Button Power 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 CTHS15CIC05ONOFF 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 : Jelena Milosavljevic
  • Date : Jun 2021.
  • Type : GPIO type

Software Support

We provide a library for the ButtonPower 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 ButtonPower 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 which 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;
buttonpower_cfg_t buttonpower_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
buttonpower_cfg_setup( &buttonpower_cfg );
BUTTONPOWER_MAP_MIKROBUS( buttonpower_cfg, MIKROBUS_1 );
err_t init_flag = buttonpower_init( &buttonpower, &buttonpower_cfg );
if ( PWM_ERROR == init_flag ) {
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
Delay_ms( 500 );
buttonpower_set_duty_cycle ( &buttonpower, 0.0 );
buttonpower_pwm_start( &buttonpower );
backlight_on( );
Delay_ms( 500 );
backligh_off( );
Delay_ms( 500 );
backlight_on( );
button_state = buttonpower_get_button_state( &buttonpower );
button_state_old = button_state;
log_info( &logger, " Application Task " );
}

Application Task

This function first turns the backlight on the button ON/OFF and then checks if the button has been pressed and reports the event in the console using UART communication.

void application_task ( void ) {
button_state = buttonpower_get_button_state( &buttonpower );
if ( button_state && ( button_state != button_state_old ) ) {
backligh_off( );
button_state_old = button_state;
Delay_ms( 500 );
} else if ( !button_state && ( button_state != button_state_old ) ) {
backlight_on( );
button_state_old = button_state;
Delay_ms( 500 );
}
}

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

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.


buttonpower_cfg_t
Button Power Click configuration object.
Definition: buttonpower.h:108
buttonpower_pwm_start
err_t buttonpower_pwm_start(buttonpower_t *ctx)
Button Power start PWM module.
buttonpower_t
Button Power Click driver selector.
Definition: buttonpower.h:92
buttonpower_cfg_setup
void buttonpower_cfg_setup(buttonpower_cfg_t *cfg)
Button Power configuration object setup function.
application_task
void application_task(void)
Definition: main.c:92
buttonpower_set_duty_cycle
err_t buttonpower_set_duty_cycle(buttonpower_t *ctx, float duty_cycle)
Button Power sets PWM duty cycle.
BUTTONPOWER_MAP_MIKROBUS
#define BUTTONPOWER_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: buttonpower.h:76
buttonpower_get_button_state
uint8_t buttonpower_get_button_state(buttonpower_t *ctx)
Button Power get button state function.
application_init
void application_init(void)
Definition: main.c:47
buttonpower_pwm_stop
err_t buttonpower_pwm_stop(buttonpower_t *ctx)
Button Power stop PWM module.
buttonpower_init
err_t buttonpower_init(buttonpower_t *ctx, buttonpower_cfg_t *cfg)
Button Power initialization function.