DebounceFilter - PaulMurrayCbr/DebounceInput GitHub Wiki

DebounceFilter is the impementation of the debounce algorithm. For a discussion of how the algorithm works, see Algorithm.

You would not normally use this class directly, using DebouncedInput instead. But if your input is coming from something other than a pin, then using this class directly is an option.

Constructors

DebounceFilter()

Construct a DebounceFilter, initialising its state to false.

DebounceFilter(boolean initialState)

Construct a DebounceFilter, initialising its state to initialState.

Members

byte risingThreshhold

A value which the internal filter must exceed to change from false (LOW) to true (HIGH). The default value is 0x90. The internal filter has a maximum value of 255, which means that if you set risingThreshhold to 255, then the filter can never rise and will remain stuck in the false (LOW) state.

byte fallingThreshhold

A value which the internal filter must be less than to change from true (HIGH) to false (LOW). The default value is 0x70. The internal filter has a minimum value of 0, which means that if you set fallingThreshhold to 0, then the filter can never fall and will remain stuck in the true (HIGH) state.

Methods

void addSample(boolean sample)

Add a sample to the filter.

state()

Get the debounced signal.

stateChanged()

True if the debounced signal changes as a result of the most recent sample.

reset(boolean state)

Reset the filter to the given state. This has the effect of saturating the filter. stateChanged will return false irrespective of whether the reset caused the state to change.