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

Issue with LongPress crashing the MCU code. #96

Closed njordan77 closed 2 years ago

njordan77 commented 2 years ago

Hi, did setup a simple button/output example that will react on double click and keep the output ON for 6secs.......and so on. I have no use for longpressed and did not put any code into my ATmega328p. To check for stability i simply did press LONG on the button and now the system does not react anymore to my double clicks, did wait for an hour but only repairs itself after a power off-on.

Any idea if i did anything wrong...my idea was that if i ignore longpress in my code it would simply ignore it completely....but this is not the case, or better said it kills the whole system.

Kind Regards Norbert

#include "OneButton.h"
OneButton button(2, true);

boolean kickoff = false;
int starttime = 0;

void setup()
{
  pinMode(4, OUTPUT);
  digitalWrite(4,LOW);
  button.attachDoubleClick(doubleClick);
}

void loop()
{
  button.tick();
  if (kickoff) {
    if ((millis() - starttime) > 6000) {
      kickoff = false;
      digitalWrite(4,LOW);
    }
  }
  delay(10);
}

void doubleClick()
{
  digitalWrite(4, HIGH);
  kickoff = true;
  starttime = millis();
}
mathertel commented 2 years ago

Just a type error. starttime needs to be defined with unsigned long.