21 #ifndef DEBOUNCER_HPP_INCLUDED 22 #define DEBOUNCER_HPP_INCLUDED 31 unsigned (*time_func)(void),
32 unsigned int time_freq,
33 unsigned wait_time_ms = 50
41 static constexpr
unsigned wait_time_ticks = (((
unsigned long long)time_freq * (
unsigned long long)wait_time_ms) / 1000L);
45 debouncer(T _value) : value(_value), current(_value), hold_time(0) { };
52 T new_value = poll_func();
53 unsigned now = time_func();
54 if(current != new_value) {
56 hold_time = now + wait_time_ticks;
59 if((hold_time > now) || (value == current))
75 #endif // DEBOUNCER_HPP_INCLUDED debouncer(T _value)
Definition: debouncer.hpp:45
bool poll(void)
Feed debouncer with a new value.
Definition: debouncer.hpp:51
Debounce a value on a given time base.
Definition: debouncer.hpp:35