Skip to main content

AnalogSensor

Base class for analog input components that read continuous values (e.g. potentiometer, light sensor). Reads analog pins (A0–A5) and emits change events when the value shifts beyond a configurable threshold.

#Extends

#Extended by

  • Potentiometer

#Constructors

#Constructor

TypeScript
new AnalogSensor(options): AnalogSensor;

#Parameters

ParameterType
optionsAnalogSensorOptions

#Returns

AnalogSensor

#Overrides

ComponentBase.constructor

#Accessors

#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

#Inherited from

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 ComponentEventMap<number>
#Parameters
ParameterType
eventK
listenerComponentEventMap<number>[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 ComponentEventMap<number>
#Parameters
ParameterType
eventK
listenerComponentEventMap<number>[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 ComponentEventMap<number>
#Parameters
ParameterType
eventK
listenerComponentEventMap<number>[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 ComponentEventMap<number>
#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 ComponentEventMap<number>
#Parameters
ParameterType
eventK
listenerComponentEventMap<number>[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;

#Parameters

ParameterType
optionsPartial<Pick<AnalogSensorOptions, "threshold" | "invert">>

#Returns

void