/////////////////////////////////////////////////////////////////
#include "Button2.h"
/////////////////////////////////////////////////////////////////
#define BUTTON_PIN_1 13
#define BUTTON_PIN_2 12
/////////////////////////////////////////////////////////////////
//Button2 button_1;
//Button2 button_2;
Button2 button_12;
typedef unsigned long TimeT;
unsigned long now = 0;
//byte counter = 0;
//byte state = 0;
byte i = 0; //licznik do eliminowania zdarzen przycisków
byte k = 0; //kod klawsza(zdażeń)
byte s = 0; //wywołano podwujne kliknięcie dwoma prxycisksmi kody specyjalne
TimeT tbutton_time = 0;
byte sr = 0;
/////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(115200);
delay(50);
Serial.println("\n\nMulti Handler Demo");
/*
button_1.begin(BUTTON_PIN_1);
button_1.setClickHandler(handler);
button_1.setDoubleClickHandler(handler);
button_1.setDebounceTime(5);
button_1.setLongClickTime(200);
button_1.setDoubleClickTime(199);
button_1.setLongClickDetectedHandler(longClickDetected);
button_1.setLongClickHandler(handler); // this will only be called upon detection
button_2.begin(BUTTON_PIN_2);
button_2.setClickHandler(handler);
button_2.setDoubleClickHandler(handler);
button_2.setDebounceTime(5);
button_2.setLongClickTime(200);
button_2.setDoubleClickTime(199);
button_2.setLongClickDetectedHandler(longClickDetected);
button_2.setLongClickHandler(handler); // this will only be called upon detection
*/
button_12.begin(BUTTON_PIN_1 && BUTTON_PIN_2);
button_12.setClickHandler(handler);
button_12.setDoubleClickHandler(handler);
button_12.setDebounceTime(5);
button_12.setLongClickTime(200);
button_12.setDoubleClickTime(199);
}
/////////////////////////////////////////////////////////////////
void loop() {
button_1.loop();
button_2.loop();
button_12.loop();
if (millis() > tbutton_time + 20 && i>0){
i=0;
switch (k){
case 1:
Serial.println(s);
if (s == 1){
Serial.println("Wszystkie Dół");
} else{
Serial.println("Dół");
}
break;
case 2:
Serial.println(s);
if (s == 1){
Serial.println("Wszystkie Góra");
} else{
Serial.println("Góra");
}
break;
case 3:
if (s == 1){
Serial.println("Progr");
}
break;
case 4:
s = 1;
Serial.println("oba_duble");
break;
;
}
}
if (millis()>tbutton_time+20 && k==5){
Serial.println("ZAS");
k=0;
}
if (millis()>tbutton_time+20 && k==6){
Serial.println("ODS");
k=0;
}
//Serial.println(s);
if (millis() > tbutton_time + 500 && s>0){
s=0;
}
}
/////////////////////////////////////////////////////////////////
void handler(Button2& btn) {
tbutton_time = millis();
unsigned int time1b = 0;
unsigned int time2b = 0;
k = 0;
time1b = (button_1.wasPressedFor());
time2b = (button_2.wasPressedFor());
switch (btn.getType()) {
case single_click:
if (btn == button_1) {
k = 1;
i++;
}
if (btn == button_2) {
k = 2;
i++;
i++;
}
if (i == 3 ){
k = 3;
}
break;
case double_click:
if (btn == button_1)
{
i++;
}
if (btn == button_2)
{
i++;
i++;
if (btn == button_12)
{
Serial.println("time12");
}
}
if (i == 3){
k = 4;
tbutton_time = millis();
}
break;
case long_click:
tbutton_time = millis();
if (btn == button_1 && sr == 1){
Serial.println(time1b);
if (time1b >= 5000){
Serial.print("res");
sr=0;
}
}
if (btn == button_2 && sr == 1){
Serial.println(time2b);
if (time2b >= 5000){
Serial.print("res w");
sr=0;
}
}
break;
}
}
/////////////////////////////////////////////////////////////////
void longClickDetected(Button2& btn) {
//byte sr = 0;
// Serial.print("long click #");
sr = s;
k++;
k++;
k++;
k++;
if ( btn == button_1) {
tbutton_time = millis();
k++;}
if (btn == button_2) {
tbutton_time = millis();
k++;
k++;
}
//Serial.print(k);
}