Digital Bank
An IO class that provides simultaneous access to a group of digital inputs or outputs.
Constructor
DigitalBank
Creates a new DigitalBank
object instance.
Parameters
options
An object of properties used to construct the class.
pins
- a bitmask with pins to include in the configuredbank
set to 1, e.g.0b1100
or(1 << 3) | (1 << 2)
will select pin 3 and 2.
mode
- A value indicating the mode of the IO, all pins use the same mode. This value may be one of the static properties on the class:DigitalBank.Input
,DigitalBank.InputPullUp
,DigitalBank.InputPullDown
,DigitalBank.InputPullUpDown
,DigitalBank.Output
,DigitalBank.OutputDrain
bank
(optional) - For devices with more than 1 digital bank of pins, a number or string value specifying the bank. Defaults to 0.
rises
- A bitmask indicating the pins which invoke theonReadable
callback when the digital signal is rising, or transitioning from 0 to 1. Must be configured if thefalls
property is not set.
falls
- A bitmask indicating the pins which invoke theonReadable
callback when the digital signal is falling, or transitioning from 1 to 0. Must be configured if therises
property is not set.
onReadable(triggered)
(optional): A callback function that is invoked when the input signals change depending on therises
orfalls
properties with thetriggered
argument as a bitmask of the pins invoking the callback.
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.
Static Properties
Input
The IO class will invoke the onReadable
callback based on the edge
value and accepts the read
method. It will read whatever logic level is connected to it and ‘float’ to random high or low values if nothing is connected
InputPullUp
An input peripheral with the default value as “pulled high”, or 1, when nothing else is connected.
InputPullDown
An input peripheral with the default value as “pulled low”, or 0, when nothing else is connected.
InputPullUpDown
‘Output’
The IO class accepts the write
method to set the configured pins in push-pull mode: low (0) or high (1).
OutputDrain
The IO class accepts the write
method to set the configured pins in open drain mode: low (0) or floating disconnected (1).
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 digital data from the IO instance.
Return value
A bitmask of the configured pins’ current value as 0 (low) or 1 (high) set in the respective bit field.
write
Sends digital data to the IO instance.
Parameters
bitmask
A bitmask of the configured pins’ current value with 0 (low) or 1 (high) set in the respective bit field.
Examples
The class can be imported from the embedded
namespace or found on the host device
global object:
Hello Blinky(s)
This example instantiates a bank of digital outputs to control a series of LEDs on pins 12 through 15 and toggle it on/off every 200 milliseconds using System.setInterval
.
Button-controlled LED
This example instantiates a bank of a single digital input to read a push button to toggle a digital output LED. The button is configured to trigger the onReadable
callback when has been pushed (falling) and released (rising) due to the InputPullUp
mode.
Rise or fall
This example instantiates a bank of digital inputs to monitor two buttons on pins 1 and 15, triggering when 1 rises or 15 falls.