Members
-
<readonly> level :number
-
Description
Return the current value, scaled [0,1]Details
-
limit :Array.<number>
-
Description
Limits the output rangeDetails
-
threshold :number
-
Description
The minimum amount of change required to emit a "change" eventDetails
-
interval :number
-
Description
The interval between readings (in ms)Details
-
smoothing :number
-
Description
The number of samples to take before finding the medianDetails
-
aref :number
-
Description
The reference voltageDetails
-
samples :number
-
Description
The number of samples to take before finding the medianDetails
-
<readonly> range :Array.<number>
-
Description
The input range of the sensorDetails
-
<readonly> raw :number
-
Description
Get the most recent raw ADC readingDetails
-
<readonly> median :number
-
Description
Get the most recent median ADC readingDetails
-
<readonly> resolution :number
-
Description
The maximum possible ADC readingDetails
-
<readonly> scaled :number
-
Description
Get the most recent scaled raw readingDetails
-
<readonly> value :number
-
Properties
Name Type Description Get
the most recent scaled median value Details
Methods
-
on( event, listener )
-
Description
Create an event listenerParameters
Name Type Description event
string The name of the event to listen for listener
function A callback to run when the event is fired. Details
-
within( range, unit, callback )
-
Description
Fire a callback when the value is within a certain rangeParameters
Name Type Description range
Array.<number> The upper and lower ends of the range to watch unit
string The property to test callback
function A callback to run when the event is fired. Details
-
removeListener( event, listener )
-
Description
Remove an event listenerParameters
Name Type Description event
string The name of the event that we are removing a listener from listener
function The callback that we are removing Details
-
once( event, listener )
-
Description
Create an event listener that will only fire one time.Parameters
Name Type Description event
string The name of the event to listen for listener
function A callback to run when the event is fired. Details
-
configure( options ) → {Sensor}
-
Description
Configure a SensorParameters
Name Type Description options
object Device configuration options Name Type Attributes Default Description aref
number <optional> 3.3 Analog reference voltage enabled
boolean <optional> true Wether the device is currently performing reads every ms interval
number <optional> 100 Interval between readings in millseconds limit
Array.<number> <optional> Limit the output range range
Array.<number> <optional> [0, N] The input range of the sensor scale
Array.<number> <optional> [0, N] The output range for the sensor's value threshold
number <optional> 1 The minimum amount of change required to emit a "change" event Returns
Examples
import Sensor from "j5e/sensor"; const sensor = await new Sensor({ pin: 12 }); sensor.configure({ interval: 500 }); sensor.on("change", data => { trace(data); });
Details
-
enable() → {Object}
-
Description
Enable a disabled sensor.Returns
Examples
import Sensor from "j5e/sensor"; const sensor = await new Sensor(12); sensor.disable(); // Wait 5 seconds and then take readings timer.setTimeout(function() { sensor.enable(); });
Details
-
disable() → {Object}
-
Description
Disable an enabled sensor.Returns
Examples
import Sensor from "j5e/sensor"; const sensor = await new Sensor(12); // Take reading for 5 seconds and then stop timer.setTimeout(function() { sensor.disable(); });
Details
-
read() → {Number}
-
Description
Synchronous read of a sensor.Returns
Examples
import Sensor from "j5e/sensor"; const sensor = await new Sensor(12); let myValue = sensor.read();
Details
-
scale( low, high [, low, high ] ) → {Object}
-
Description
scale/scaleTo Set a value scaling rangeParameters
Name Type Attributes Description low
Number Lowerbound high
Number Upperbound low, high
Array <optional> Lowerbound Returns
Examples
import Sensor from "j5e/sensor"; const sensor = await new Sensor(12); // Scale all future values to 8-bit range sensor.scale([0, 255]);
Details
-
scaleTo( low, low, high ) → {Number}
-
Description
scaleTo Scales value to integer representationParameters
Name Type Description low
Number An array containing a lower and upper bound low
Number A number to use as a lower bound high
Number A number to use as an upper bound Returns
Examples
import Sensor from "j5e/sensor"; const sensor = await new Sensor(12); // Scale the returned value to 8-bit range sensor.scaleTo([0, 255]);
Details
-
fscaleTo( low, low, high ) → {Number}
-
Description
fscaleTo Scales value to single precision float representationParameters
Name Type Description low
Number An array containing a lower and upper bound low
Number A number to use as a lower bound high
Number A number to use as an upper bound Returns
Examples
import Sensor from "j5e/sensor"; const sensor = await new Sensor(12); // Scale the returned value to float between 0 and 1 sensor.fscaleTo([0, 1]);
Details