#include "OneButton.h" // https://github.com/mathertel/OneButton
// Setup a new OneButton on pin PIN_INPUT
// The 2. parameter activeLOW is true, because external wiring sets the button to LOW when pressed.
OneButton button(A0, true);
// In case the momentary button puts the input to HIGH when pressed:
// The 2. parameter activeLOW is false when the external wiring sets the button to HIGH when pressed.
// The 3. parameter can be used to disable the PullUp .
// OneButton button(PIN_INPUT, false, false);
/*
ICACHE_RAM_ATTR void checkTicks() {
// include all buttons here to be checked
button.tick(); // just call tick() to check the state.
}*/
void setup() {
Serial.begin(115200);
button.attachClick(singleclick);
button.attachDoubleClick(doubleclick);
button.attachMultiClick(multiClick);
button.attachDuringLongPress(longPress);
button.attachLongPressStart(longPressStart);
button.attachLongPressStop(longPressStop);
}
void loop() {
unsigned long currentTime = millis();
button.tick(); // keep watching the push buttons:
}
// This function will be called when the button was pressed 1 time (and no 2. button press followed).
void singleclick(){
Serial.println("singleclick detected.");
/* previousTime_1 = currentTime;
if (( currentTime - previousTime_1 ) >= eventTime_1 ) {
}
previousTime_1_LipoV = currentTime;*/
} // singleclick
// This function will be called when the button was pressed 2 times in a short timeframe.
void doubleclick(){
Serial.println("doubleclick detected.");
} // doubleclick
// This function will be called when the button was pressed multi times in a short timeframe.
void multiClick() {
int c = button.getNumberClicks();
if (c == 3) {
Serial.println("tripleClick detected.");
} else if (c == 4) {
Serial.println("quadrupleClick detected.");
} else {
Serial.print("multiClick(");
Serial.print(c);
Serial.println(") detected.");
}
} // multiClick
// This function will be called often, while the button is pressed for a long time.
void longPress() {
Serial.println("longPress detected.");
} // longPress
// This function will be called once, when the button is pressed for a long time.
void longPressStart() {
Serial.println("longPress start detected.");
} // longPressStart
// This function will be called once, when the button is released after beeing pressed for a long time.
void longPressStop() {
Serial.println("longPress stop detected.");
} // longPressStop