Module: j5e/thermometer
Description
A module for measuring temperature using a 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
Device Specific Modules
Class: Thermometer
The Thermometer class allows for control of analog thermistors
Constructor
new Thermometer(io)
Parameters
(required)
Description:
Pin identifier or IO Options (See instantiation)
Examples
// Use a thermometer
import Thermometer from "j5e/thermometer";
const myThermometer = await new Thermometer(12);
// Pass in a custom toCelsius function
import Thermometer from "j5e/thermometer";
const myThermometer = await new Thermometer({
pin: 12
});
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
Thermometer.configure
Configure a Thermometer
thermometer.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 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);
});
Thermometer.enable
Enable a disabled sensor.
thermometer.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();
});
Thermometer.disable
Disable an enabled sensor.
thermometer.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();
});
Thermometer.read
Synchronous read of a sensor.
thermometer.read();
Returns: sensor value
Example
import Sensor from "j5e/sensor";
const sensor = await new Sensor(12);
let myValue = sensor.read();
Thermometer.scale
scale/scaleTo Set a value scaling range
thermometer.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]);
Thermometer.scaleTo
scaleTo Scales value to integer representation
thermometer.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]);
Thermometer.fscaleTo
fscaleTo Scales value to single precision float representation
thermometer.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]);
Thermometer.within
Fire a callback when the value is within a certain range
thermometer.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.
Thermometer.on
Create an event listener
thermometer.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.
Thermometer.removeListener
Remove an event listener
thermometer.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
Thermometer.emit
Note: This method is not part of the public API, and is subject to change.
Emit an event
thermometer.emit(event);
Parameters
(required)
Description:
The name of the event to emit
Thermometer.once
Create an event listener that will only fire one time.
thermometer.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.