new <async> LM35( io )

Description
The LM35 class allows for reading of LM35 thermistors
Parameters
Name Type Description
io number | string | object Pin identifier or IO Options (See Instantiating a Device)
Examples

Use a LM35

import LM35 from "j5e/lm35";
			
			const myLM35 = await new LM35(12);
			
			myLM35.on("change", function(data) {
			  trace(data.C);
			});
Fires

Members


<readonly> celsius :number

Description
Get degrees in celsius
Examples

Get degrees in celsius in action

import Thermometer from "j5e/thermometer";
			
			const myThermometer = await new Thermometer(12);
			myThermometer.on("change", function() {
			  console.log(myThermometer.celsius);

<readonly> C :number

Description
Alias for celsius
Examples

Get degrees in celsius in action

import Thermometer from "j5e/thermometer";
			
			const myThermometer = await new Thermometer(12);
			myThermometer.on("change", function() {
			  console.log(myThermometer.C);

limit :Array.<number>

Description
Limits the output range
Details
Array.<number>

threshold :number

Description
The minimum amount of change required to emit a "change" event

<readonly> fahrenheit :number

Description
Get degrees in fahrenheit
Examples

Get degrees in fahrenheit in action

import Thermometer from "j5e/thermometer";
			
			const myThermometer = await new Thermometer(12);
			myThermometer.on("change", function() {
			  console.log(myThermometer.fahrenheit);

interval :number

Description
The interval between readings (in ms)

<readonly> F :number

Description
Alias for fahrenheit
Examples

Get degrees in fahrenheit in action

import Thermometer from "j5e/thermometer";
			
			const myThermometer = await new Thermometer(12);
			myThermometer.on("change", function() {
			  console.log(myThermometer.F);

smoothing :number

Description
The number of samples to take before finding the median

<readonly> kelvin :number

Description
Get degrees in kelvin
Examples

Get degrees in kelvin in action

import Thermometer from "j5e/thermometer";
			
			const myThermometer = await new Thermometer(12);
			myThermometer.on("change", function() {
			  console.log(myThermometer.kelvin);

aref :number

Description
The reference voltage

<readonly> K :number

Description
Alias for kelvin
Examples

Get degrees in kelvin in action

import Thermometer from "j5e/thermometer";
			
			const myThermometer = await new Thermometer(12);
			myThermometer.on("change", function() {
			  console.log(myThermometer.K);

samples :number

Description
The number of samples to take before finding the median

<readonly> range :Array.<number>

Description
The input range of the sensor
Details
Array.<number>

<readonly> raw :number

Description
Get the most recent raw ADC reading

<readonly> median :number

Description
Get the most recent median ADC reading

<readonly> resolution :number

Description
The maximum possible ADC reading

<readonly> scaled :number

Description
Get the most recent scaled raw reading

<readonly> value :number

Properties
Name Type Description
Get the most recent scaled median value

Methods


on( event, listener )

Description
Create an event listener
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.

within( range, unit, callback )

Description
Fire a callback when the value is within a certain range
Parameters
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.

removeListener( event, listener )

Description
Remove an event listener
Parameters
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

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.

configure( options ) → {Thermometer}

Description
Configure a Thermometer
Parameters
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
The instance on which the method was called
Examples

Passing in Cofiguration Options

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);
			});

enable() → {Object}

Description
Enable a disabled sensor.
Returns
instance
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();
			});

disable() → {Object}

Description
Disable an enabled sensor.
Returns
instance
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();
			});

read() → {Number}

Description
Synchronous read of a sensor.
Returns
sensor value
Examples
import Sensor from "j5e/sensor";
			const sensor = await new Sensor(12);
			
			let myValue = sensor.read();

scale( low, high [, low, high ] ) → {Object}

Description
scale/scaleTo Set a value scaling range
Parameters
Name Type Attributes Description
low Number Lowerbound
high Number Upperbound
low, high Array <optional>
Lowerbound
Returns
instance
instance
Examples
import Sensor from "j5e/sensor";
			const sensor = await new Sensor(12);
			
			// Scale all future values to 8-bit range
			sensor.scale([0, 255]);

scaleTo( low, low, high ) → {Number}

Description
scaleTo Scales value to integer representation
Parameters
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
The scaled value
Examples
import Sensor from "j5e/sensor";
			const sensor = await new Sensor(12);
			
			// Scale the returned value to 8-bit range
			sensor.scaleTo([0, 255]);

fscaleTo( low, low, high ) → {Number}

Description
fscaleTo Scales value to single precision float representation
Parameters
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
The scaled value
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]);