more simple method of debouncing to trigger a long event?

Hi,

I would like to trigger a series of events (that last about 40 seconds) upon the push of a button. The device is running 24/7 for a very long time, so power is a concern.

The Arduino example library provides a debounce code that seems pretty complex for this purpose.

I saw on one forum using a while loop to wait until the button was pushed down and then released again.

  // wait until button was pushed down...
  while (digitalRead(pin) == LOW);
  // ... and released again
  while (digitalRead(pin) == HIGH);

is this method acceptable for my purposes?

Do I need any debouncing at all? Or maybe is there a simpler way?

Let the first Bounce start the 40 second sequrce and don't read the switch during that time. Then You can forget about bounces.

You can use the library.

button.setDebounceTime(40000);

See the library's example code

fionalee33: Do I need any debouncing at all? Or maybe is there a simpler way?

That depends on all the aspects of the problem that you have not explained in your cursory description. :roll_eyes:

Power is a concern - so you mean you are using battery power and sleep modes? Sleep modes, that in turn means you'd be using some kind of interrupt to wake?

Normally you'd do state change detection to read a button, and you can start the long process the moment you see a state change. If that button has no function during the long process, you don't need debouncing. You just don't read it while that process runs.

wvmarle: Power is a concern - so you mean you are using battery power and sleep modes? Sleep modes, that in turn means you'd be using some kind of interrupt to wake?

Normally you'd do state change detection to read a button, and you can start the long process the moment you see a state change. If that button has no function during the long process, you don't need debouncing. You just don't read it while that process runs.

no, I didn't know sleep mode was a thing. I will look into that, thank you!

how do you w

Paul__B: That depends on all the aspects of the problem that you have not explained in your cursory description. :roll_eyes:

what other aspects do you mean?

fionalee33: what other aspects do you mean?

All of them. Shades of the "XY Problem".

What the sequence of events is, whether it should be retriggerable, what your button consists of, whether you actually want it to wait until the button is released as your non-debounced code snippet might imply, what should happen if the button is held down permanently?

Why power is a concern, what your power source will be and how are you connecting it?

Maybe other things ...


Anticipating your reply. :roll_eyes: