Debounce:
Filter:
Classes (extension) | Utilities

Debounce : Object
ExtensionExtension

debounce incoming signals from crackly switches.
Source: Debounce.sc

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

Debounce.new(onFunc, offFunc, size: 5)

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

Inherited class methods

Instance Methods

.isOn

.isOn = value

get and set whether debounce is now on or not

.set(val)

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

.size = value

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

.onFunc

.onFunc = value

get and set function that triggers when debounce switches to on

.offFunc

.offFunc = value

get and set function that triggers when debounce switches to off

.check

check whether to switch status

.lastN

the last n values recorded

Inherited instance methods