DebounceFilter4ms - PaulMurrayCbr/DebounceInput GitHub Wiki

DebounceFilter4ms is a subclass of DebounceFilter that is able to rate-limit samples to no more than one per 4ms

Constructors

DebounceFilter4ms()

Construct a DebounceFilter4ms, initialising its state to false.

DebounceFilter4ms(boolean initialState)

Construct a DebounceFilter4ms, 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.

void addSampleRateLimited(boolean sample)

Add a sample to the filter, selectively ignoring samples to force no more than one per 4ms. This keeps the filter behaviour consistent over time. The 'changing' bit will still be updated, to keep the behaviour that if the output does not change after a sample, changing becomes false.

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.