Btn.addButton()

This function adds desired button to button set. Each button indentifies via its pin number. You are able to use tact-buttons and capacitite buttons.
Btn.addButton(pin)
Btn.addButton(pin, type)
Btn.addButton(pin, init)
pin: Pin to which the button is connected. type: Defines button type.
  • BtnTypeButton (the default) - tact button (mechanical button)
  • BtnTypeTouch - capacitive button (capacitive pad)
init: pointer to ZunoBtnButtonInit_t structure. This allows you to fine tune the behavior of the button.
Result of operation. If value differs from ZunoErrorOk it means that operation was failed.
		
typedef struct							ZunoBtnDelayInit_s // This structure holds time intervals for button library
{
	uint16_t							delayDebounce;  // Debounce delay interval in ms
	uint16_t							delaySingleClick; // Single click check interval in ms
	uint16_t							delayLongClick; // Long click detection interval in ms
	uint16_t							delayFree; // Button release interval in ms
}										ZunoBtnDelayInit_t;

typedef enum // Tact button modes enumeration
{
	BtnButtonModeAuto, // This mode automatically selects timer or interrups approach depends on power mode 
	BtnButtonModeTimer,// Uses system timer for button processing
	BtnButtonModeExtInt// Uses external inetrrups for button processing
} ZunoButtonMode_t;

typedef struct							ZunoBtnButtonInit_s // Initial structure for tact-buttons
{
	ZunoBtnDelayInit_t					delay; // custom time intervals for button 
	ZunoButtonMode_t					mode;  // Defines dispatch mode 
	uint8_t								bInvert;// Defines that logic 1 is idle state of button. Default is true
}										ZunoBtnButtonInit_t;

typedef struct							ZunoBtnTouchInit_s // Initial structure for capacitive-buttons
{
	ZunoBtnDelayInit_t					delay; // custom time intervals for button 
	uint8_t								clickPower; // Power percentage of button
}										ZunoBtnTouchInit_t;
		
	
Please note that if you use mode BtnButtonModeExtInt there are hardware pin-restrictions, you can use only one of pin listed in parentheses for buttons: 0, (1/5), (2/15), (3/21), (4/22), (6/23), (7/17), 8, (9/20/25), (10/19), 11, 12, 13, 14, 16, (18/24) Example that shows how to use non-default parameters for tact-button. We use here macro BTN_BUTTON_INIT_DEFAULT ( for capacitive button BTN_TOUCH_INIT_DEFAULT):

#include "ZUNO_Buttons.h"
#define MY_SERIAL Serial0
#define BUTTON		23

uint8_t dimmerValue = 100;

// the setup function runs once, when you press reset or power the board
void setup() {
	ZunoBtnButtonInit_t			init;

	MY_SERIAL.begin();
	MY_SERIAL.println("Setup");
	pinMode(LED_BUILTIN, OUTPUT);
	init = BTN_BUTTON_INIT_DEFAULT;
	init.delay.delaySingleClick = 60;// Change time interval of single click
	init.mode = BtnButtonModeTimer; // We say library to use system timer for processing 
	Btn.addButton(BUTTON, &init);
}

// the loop function runs over and over again forever
void loop() {
	digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
	delay(dimmerValue*10);           // wait for timeout
	digitalWrite(LED_BUILTIN, LOW);  // turn the LED off by making the voltage LOW
	delay(dimmerValue*10);           // wait for timeout
	process_buttons();
	MY_SERIAL.println("Loop");
}

void process_buttons() {
	if(Btn.isSingleClick(BUTTON)) {
		Serial0.println("isSingleClick");
		if (dimmerValue == 5)
			dimmerValue = 100;
		else
			dimmerValue = 5;
	}
	if(Btn.isTripleClick(BUTTON)) {
		Serial0.println("isTripleClick");
		if (dimmerValue == 5)
			dimmerValue = 100;
		else
			dimmerValue = 5;
	}
	if(Btn.isLongClick(BUTTON)) {
		Serial0.println("isLongClick");
		if (dimmerValue == 5)
			dimmerValue = 100;
		else
			dimmerValue = 5;
	}
	if(Btn.isDoubleClick(BUTTON)) {
		Serial0.println("isDoubleClick");
		if (dimmerValue == 5)
			dimmerValue = 100;
		else
			dimmerValue = 5;
	}
}