Module: j5e/lm335
Description
A module for measuring temperature using a LM335 thermistor.
A thermistor is a type of resistor whose resistance is strongly dependent on temperature, more so than in standard resistors. The word thermistor is a portmanteau of thermal and resistor.Read more on Wikipedia
Requires
Class: LM335
The LM335 class allows for reading of LM335 thermistors
Constructor
new LM335(io)
Parameters
(required)
Description:
Pin identifier or IO Options (See instantiation)
Example
// Use a LM335
import LM335 from "j5e/lm335";
const myLM335 = await new LM335(12);
myLM335.on("change", function(data) {
trace(data.C);
});
Properties
(read only)
(read only)
(read only)
(read only)
(read only)
(read only)
(read only)
(read only)
(read only)
(read only)
(read only)
(read only)
Events
- event:data
- event:change
Methods
LM335.configure
Configure an LM335
lm335.configure(options);
Returns: The instance on which the method was called
Parameters
(required)
Description:
Device configuration options
Description:
Analog reference voltage
Default: 3.3
Description:
Wether the device is currently performing reads every
Default: true
Description:
Interval between readings in millseconds
Default: 100
Description:
Limit the output range
Description:
The input range of the sensor
Default: [0, N]
Description:
The output range for the sensor's value
Default: [0, N]
Description:
The minimum amount of change required to emit a "change" event
Default: 1
Description:
Function that converts raw value to Celsius
Example
// Passing in Cofiguration Options
import LM335 from "j5e/lm335";
const thermometer = await new LM335({
pin: 14
});
thermometer.on("change", data => {
trace(thermometer.celsius);
});
LM335.enable
Enable a disabled sensor.
lm335.enable();
Returns: instance
Example
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();
});
LM335.disable
Disable an enabled sensor.
lm335.disable();
Returns: instance
Example
import Sensor from "j5e/sensor";
const sensor = await new Sensor(12);
// Take reading for 5 seconds and then stop
timer.setTimeout(function() {
sensor.disable();
});
LM335.read
Synchronous read of a sensor.
lm335.read();
Returns: sensor value
Example
import Sensor from "j5e/sensor";
const sensor = await new Sensor(12);
let myValue = sensor.read();
LM335.scale
scale/scaleTo Set a value scaling range
lm335.scale(low, high, low, high);
Returns: instance
Parameters
(required)
Description:
Lowerbound
(required)
Description:
Upperbound
Description:
Lowerbound
Example
import Sensor from "j5e/sensor";
const sensor = await new Sensor(12);
// Scale all future values to 8-bit range
sensor.scale([0, 255]);
LM335.scaleTo
scaleTo Scales value to integer representation
lm335.scaleTo(low, low, high);
Returns: The scaled value
Parameters
(required)
Description:
An array containing a lower and upper bound
(required)
Description:
A number to use as a lower bound
(required)
Description:
A number to use as an upper bound
Example
import Sensor from "j5e/sensor";
const sensor = await new Sensor(12);
// Scale the returned value to 8-bit range
sensor.scaleTo([0, 255]);
LM335.fscaleTo
fscaleTo Scales value to single precision float representation
lm335.fscaleTo(low, low, high);
Returns: The scaled value
Parameters
(required)
Description:
An array containing a lower and upper bound
(required)
Description:
A number to use as a lower bound
(required)
Description:
A number to use as an upper bound
Example
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]);
LM335.within
Fire a callback when the value is within a certain range
lm335.within(range, unit, callback);
Parameters
(required)
Description:
The upper and lower ends of the range to watch
(required)
Description:
The property to test
(required)
Description:
A callback to run when the event is fired.
LM335.on
Create an event listener
lm335.on(event, listener);
Parameters
(required)
Description:
The name of the event to listen for
(required)
Description:
A callback to run when the event is fired.
LM335.removeListener
Remove an event listener
lm335.removeListener(event, listener);
Parameters
(required)
Description:
The name of the event that we are removing a listener from
(required)
Description:
The callback that we are removing
LM335.emit
Note: This method is not part of the public API, and is subject to change.
Emit an event
lm335.emit(event);
Parameters
(required)
Description:
The name of the event to emit
LM335.once
Create an event listener that will only fire one time.
lm335.once(event, listener);
Parameters
(required)
Description:
The name of the event to listen for
(required)
Description:
A callback to run when the event is fired.