Hi everyone.
The example sketch from button2.h
/////////////////////////////////////////////////////////////////
#include "Button2.h"
/////////////////////////////////////////////////////////////////
#define BUTTON_PIN 2
/////////////////////////////////////////////////////////////////
Button2 button;
/////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
delay(50);
Serial.println("\n\nButton Demo");
button.begin(BUTTON_PIN);
// button.setLongClickTime(1000);
// button.setDoubleClickTime(400);
Serial.println(" Longpress Time:\t" + String(button.getLongClickTime()) + "ms");
Serial.println(" DoubleClick Time:\t" + String(button.getDoubleClickTime()) + "ms");
Serial.println();
// button.setChangedHandler(changed);
// button.setPressedHandler(pressed);
button.setReleasedHandler(released);
// button.setTapHandler(tap);
button.setClickHandler(click);
button.setLongClickDetectedHandler(longClickDetected);
button.setLongClickHandler(longClick);
button.setDoubleClickHandler(doubleClick);
button.setTripleClickHandler(tripleClick);
}
/////////////////////////////////////////////////////////////////
void loop() {
button.loop();
}
/////////////////////////////////////////////////////////////////
void pressed(Button2& btn) {
Serial.println("pressed");
}
void released(Button2& btn) {
Serial.print("released: ");
Serial.println(btn.wasPressedFor());
}
void changed(Button2& btn) {
Serial.println("changed");
}
void click(Button2& btn) {
Serial.println("click\n");
}
void longClickDetected(Button2& btn) {
Serial.println("long click detected");
}
void longClick(Button2& btn) {
Serial.println("long click\n");
}
void doubleClick(Button2& btn) {
Serial.println("double click\n");
}
void tripleClick(Button2& btn) {
Serial.println("triple click\n");
}
void tap(Button2& btn) {
Serial.println("tap");
}
Serial Monitor:
long click detected
released: 1024
long click
it is the output when pressed button once, should it output all void result such as and why didn't:
pressed
released = 1024
changed
click/1
etc....
thanks
Adam