Debounce:
Filter:
adclib/Classes (extension) | Utilities

Debounce
ExtensionExtension

debounce incoming signals from crackly switches.

Description

Debounce is intended for cleaning up incoming signals from e.g. Arduinos that represent switching buttons. Such buttons often produce occasional wrong values, reporting e.g. off when the switch is on. Debouncing filters such signals, requiring at least e.g. 5 positiv values before actually switching to on.

Class Methods

.new

Arguments:

onFunc

a function that runs when on condition is reached

offFunc

a function that runs when off condition is reached

size

the list of how many lastN values to keep

Instance Methods

.isOn

get and set whether debounce is now on or not

.set

enter next value, and if change of status happened, run onFunc or offFunc

Arguments:

val

0 or 1

.sum

the current sum of lastN values

.size

get and set size of the list of how many lastN values to keep

.onFunc

get and set function that triggers when debounce switches to on

.offFunc

get and set function that triggers when debounce switches to off

.check

check whether to switch status

.lastN

the last n values recorded