new <async> Light( io )

Description
The Light class allows for control of photoresistors
Parameters
Name Type Description
io number | string | object Pin identifier or IO Options (See Instantiating a Device)
Properties
Name Type Description
level number Get the light level scaled to [0, 1] to two decimal places
Examples

Use a photoresistor

import Light from "j5e/light";
			
			const light = await new Light(12);
			
			light.on("change", data => {
			  trace(light.level);
			})
Fires
Details

Members


<readonly> level :number

Description
Return the current value, scaled [0,1]
Details
number

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

interval :number

Description
The interval between readings (in ms)

smoothing :number

Description
The number of samples to take before finding the median

aref :number

Description
The reference voltage
Details
number

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
Details
number

<readonly> median :number

Description
Get the most recent median ADC reading
Details
number

<readonly> resolution :number

Description
The maximum possible ADC reading

<readonly> scaled :number

Description
Get the most recent scaled raw reading
Details
number

<readonly> value :number

Properties
Name Type Description
Get the most recent scaled median value
Details
number

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 ) → {Sensor}

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

Passing in Cofiguration Options

import Sensor from "j5e/sensor";
			
			const sensor = await new Sensor({
			 pin: 12
			});
			
			sensor.configure({
			 interval: 500
			});
			
			sensor.on("change", data => {
			 trace(data);
			});

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