diff --git a/lib/button.js b/lib/button.js index 80098809d..a414afe26 100644 --- a/lib/button.js +++ b/lib/button.js @@ -182,13 +182,6 @@ class Button extends Emitter { last: null }; - // Create a debounce boundary on event triggers - // this avoids button events firing on - // press noise and false positives - const trigger = Fn.debounce(key => { - aliases[key].forEach(type => this.emit(type)); - }, 7); - let pinValue = typeof options === "object" ? options.pin : options; Board.Component.call( @@ -210,6 +203,11 @@ class Button extends Emitter { this.pulldown = options.pulldown || options.isPulldown || false; + // `debounceTime` is a duration (milliseconds) + // to prevent button events firing on + // press noise and false positives + this.debounceTime = options.debounceTime || 7; + // Turns out some button circuits will send // 0 for up and 1 for down, and some the inverse, // so we can invert our function with this option. @@ -275,6 +273,13 @@ class Button extends Emitter { } }); + // Create a debounce boundary on event triggers + // this avoids button events firing on + // press noise and false positives + const trigger = Fn.debounce(key => { + aliases[key].forEach(type => this.emit(type)); + }, this.debounceTime); + /* istanbul ignore else */ if (typeof this.initialize === "function") { this.initialize(options, data => {