Skip to main content

Button

Base class for button and switch components with software debouncing and hold detection.

#Extends

#Constructors

#Constructor

TypeScript
new Button(options): Button;

#Parameters

ParameterType
optionsButtonOptions

#Returns

Button

#Overrides

ComponentBase.constructor

#Accessors

#isPressed

#Get Signature

TypeScript
get isPressed(): boolean;

Check if the button is currently pressed

#Returns

boolean


#value

#Get Signature

TypeScript
get value(): T | undefined;

Get the current value of the component.

#Returns

T | undefined

#Inherited from

ComponentBase.value

#Methods

#cleanup()

TypeScript
cleanup(): void;

Cleanup resources when board closes. Override in subclasses to add component-specific cleanup.

#Returns

void

#Overrides

ComponentBase.cleanup


#handleData()

TypeScript
handleData(data): void;

Handle incoming data from Arduino via serial protocol. Called by Board when data arrives for this component's ID.

#Parameters

ParameterType
dataunknown

#Returns

void

#Overrides

ComponentBase.handleData


#off()

#Call Signature

TypeScript
off<K>(event, listener): this;

Alias for removeListener (Node.js EventEmitter compatibility).

#Type Parameters
Type Parameter
K extends keyof ButtonEventMap
#Parameters
ParameterType
eventK
listenerButtonEventMap[K]
#Returns

this

#Inherited from

ComponentBase.off

#Call Signature

TypeScript
off(event, listener): this;

Alias for removeListener (Node.js EventEmitter compatibility).

#Parameters
ParameterType
eventstring | symbol
listener(...args) => void
#Returns

this

#Inherited from

ComponentBase.off


#on()

#Call Signature

TypeScript
on<K>(event, listener): this;

Register an event listener with typed events.

#Type Parameters
Type Parameter
K extends keyof ButtonEventMap
#Parameters
ParameterType
eventK
listenerButtonEventMap[K]
#Returns

this

#Inherited from

ComponentBase.on

#Call Signature

TypeScript
on(event, listener): this;

Register an event listener with typed events.

#Parameters
ParameterType
eventstring | symbol
listener(...args) => void
#Returns

this

#Inherited from

ComponentBase.on


#once()

#Call Signature

TypeScript
once<K>(event, listener): this;

Register a one-time event listener with typed events.

#Type Parameters
Type Parameter
K extends keyof ButtonEventMap
#Parameters
ParameterType
eventK
listenerButtonEventMap[K]
#Returns

this

#Inherited from

ComponentBase.once

#Call Signature

TypeScript
once(event, listener): this;

Register a one-time event listener with typed events.

#Parameters
ParameterType
eventstring | symbol
listener(...args) => void
#Returns

this

#Inherited from

ComponentBase.once


#removeAllListeners()

#Call Signature

TypeScript
removeAllListeners<K>(event?): this;

Remove all listeners for a specific event, or all events if no event specified.

#Type Parameters
Type Parameter
K extends keyof ButtonEventMap
#Parameters
ParameterType
event?K
#Returns

this

#Inherited from

ComponentBase.removeAllListeners

#Call Signature

TypeScript
removeAllListeners(event?): this;

Remove all listeners for a specific event, or all events if no event specified.

#Parameters
ParameterType
event?string | symbol
#Returns

this

#Inherited from

ComponentBase.removeAllListeners


#removeListener()

#Call Signature

TypeScript
removeListener<K>(event, listener): this;

Remove an event listener with typed events.

#Type Parameters
Type Parameter
K extends keyof ButtonEventMap
#Parameters
ParameterType
eventK
listenerButtonEventMap[K]
#Returns

this

#Inherited from

ComponentBase.removeListener

#Call Signature

TypeScript
removeListener(event, listener): this;

Remove an event listener with typed events.

#Parameters
ParameterType
eventstring | symbol
listener(...args) => void
#Returns

this

#Inherited from

ComponentBase.removeListener


#setBoard()

TypeScript
setBoard(board): void;

#Parameters

ParameterType
boardBoard

#Returns

void

#Inherited from

ComponentBase.setBoard


#updateOptions()

TypeScript
updateOptions(options): void;

Update runtime options such as invert direction.

#Parameters

ParameterType
options{ invert?: boolean; }
options.invert?boolean

#Returns

void