arduino-audio-tools
Debouncer.h
1 #pragma once
2 
3 namespace audio_tools {
4 
9  class Debouncer {
10 
11  public:
12  Debouncer(uint16_t timeoutMs = 5000, void* ref = nullptr) {
13  setDebounceTimeout(timeoutMs);
14  p_ref = ref;
15  }
16 
17  void setDebounceTimeout(uint16_t timeoutMs) {
18  ms = timeoutMs;
19  }
20 
22  bool debounce(void(*cb)(void* ref) = nullptr) {
23  bool result = false;
24  if (millis() > debounce_ms) {
25  LOGI("accpted");
26  if (cb != nullptr) cb(p_ref);
27  // new time limit
28  debounce_ms = millis() + ms;
29  result = true;
30  }
31  else {
32  LOGI("rejected");
33  }
34  return result;
35  }
36 
37  protected:
38  unsigned long debounce_ms = 0; // Debounce sensitive touch
39  uint16_t ms;
40  void* p_ref = nullptr;
41 
42  };
43 
44 }
Helper class to debounce user input from a push button.
Definition: Debouncer.h:9
bool debounce(void(*cb)(void *ref)=nullptr)
Prevents that the same method is executed multiple times within the indicated time limit.
Definition: Debouncer.h:22
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AnalogAudio.h:10
uint32_t millis()
Returns the milliseconds since the start.
Definition: Millis.h:18