Pulse Count
The IO class implements a bi-directional counter typically used with a rotary encoder.
Constructor
PulseCount
Creates a new PulseCount
object instance.
Parameters
options
An object of properties used to construct the class.
signal
- a pin specifier indicating the signal input pin.
control
- a pin specifier indicating the control input pin.
onReadable()
(optional): A callback function that is invoked when the input value changes, which can be retrieved using theread
method. Multiple changes to the counter may be combined into a single callback.
onError
(optional): A callback function that is invoked when a non-recoverable error occurs, such as underflow or overflow of the counter.
Exceptions
If the constructor requires a resource that is already in use — whether by a script or the native host — an Error
exception is thrown.
Instance Properties
Includes properties of the IO Class Pattern
. Specific to this class:
format
Always returns "number"
. The string value set by the constructor options or by the script at any time to change how it reads data.
Instance Methods
read
Returns the current count from the IO instance.
Return value
A number describing the current count.
write
Sets the current count on the IO instance.
Parameters
count
A number describing the current count.
Examples
The class can be imported from the embedded
namespace or found on the host device
global object:
Rotary encoder
This example instantiates a pulse counter to monitor a rotary encoder and log the current count when it changes.