mathertel / OneButton

An Arduino library for using a single button for multiple purpose input.
http://www.mathertel.de/Arduino/OneButtonLibrary.aspx
Other
920 stars 230 forks source link

Detecting multiple clicks returns wrong values for > 2 #132

Open theclayman opened 8 months ago

theclayman commented 8 months ago

Hello,

first thanks for this great library which saves me a lot of time for developing my smart home shutter control. I try to detect and count multiple clicks of a button, but the results for multiple clicks > 2 are not correct, while detecting single and double clicks works correctly. This is my code:

rollo1_taster_hoch = OneButton(
  CONTROLLINO_A0, // Input pin for the button
  false, // Button is active high
  true // Enable internal pull-up resistor
);
rollo1_taster_hoch.attachMultiClick(handleMultiClick);

static void handleMultiClick(OneButton *oneButton) {
  Serial.print("Number of clicks: ");
  Serial.print(oneButton->getNumberClicks());
  if(oneButton->getNumberClicks() == 5) {
    Serial.println("5 klicks");
  }
}

For 3 clicks the serial output is: "Number of clicks 55" For 4 clicks: Number of clicks 0 For 5 clicks: Number of clicks 768 For 6 clicks: Number of clicks 771

These values are reproducible when clicking the same number of times again.

Does anyone have an idea what could cause these wrong values?