Analog Input
An IO class that represents an analog input source
Constructor
Analog
Creates a new Analog
object instance.
Parameters
options
An object of properties used to construct the class.
pin
- a pin specifier indicating the analog input pin.
resolution
(optional) - The requested number of bits of resolution of the input. Default resolution is host-dependent.
format
(optional) - a string that indicates the type of data used by the read method. Defaults to, and only accepts,"number"
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.
resolution
Indicates the number of bits of resolution provided in values returned by the instance, e.g 10.
Instance Methods
read
Returns analog data from the IO instance.
Return value
An integer from 0 to a maximum value based on the resolution
of the analog input.
Examples
The class can be imported from the embedded
namespace or found on the host device
global object:
Continually poll data from input
This example instantiates an analog input and read from it every 100 milliseconds using System.setInterval
. It logs out the precise value based on the resolution
.