Members
-
<readonly> celsius :number
-
Description
Get degrees in celsiusExamples
import Thermometer from "j5e/thermometer"; const myThermometer = await new Thermometer(12); myThermometer.on("change", function() { console.log(myThermometer.celsius);
Details
-
<readonly> C :number
-
Description
Alias for celsiusExamples
import Thermometer from "j5e/thermometer"; const myThermometer = await new Thermometer(12); myThermometer.on("change", function() { console.log(myThermometer.C);
Details
-
limit :Array.<number>
-
Description
Limits the output rangeDetails
-
threshold :number
-
Description
The minimum amount of change required to emit a "change" eventDetails
-
<readonly> fahrenheit :number
-
Description
Get degrees in fahrenheitExamples
import Thermometer from "j5e/thermometer"; const myThermometer = await new Thermometer(12); myThermometer.on("change", function() { console.log(myThermometer.fahrenheit);
Details
-
interval :number
-
Description
The interval between readings (in ms)Details
-
<readonly> F :number
-
Description
Alias for fahrenheitExamples
import Thermometer from "j5e/thermometer"; const myThermometer = await new Thermometer(12); myThermometer.on("change", function() { console.log(myThermometer.F);
Details
-
smoothing :number
-
Description
The number of samples to take before finding the medianDetails
-
<readonly> kelvin :number
-
Description
Get degrees in kelvinExamples
import Thermometer from "j5e/thermometer"; const myThermometer = await new Thermometer(12); myThermometer.on("change", function() { console.log(myThermometer.kelvin);
Details
-
aref :number
-
Description
The reference voltageDetails
-
<readonly> K :number
-
Description
Alias for kelvinExamples
import Thermometer from "j5e/thermometer"; const myThermometer = await new Thermometer(12); myThermometer.on("change", function() { console.log(myThermometer.K);
Details
-
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 ) → {Thermometer}
-
Description
Configure a ThermometerParameters
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 toCelsius
callback <optional> Function that converts raw value to Celsius Returns
Examples
import Thermometer from "j5e/thermometer"; const thermometer = await new Thermometer({ pin: 14 }); myThermometer.configure({ toCelsius: function(raw) { return raw / 16; } }) ; thermometer.on("change", data => { trace(thermometer.celsius); });
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