new <async> Relay( io, options )

Description
The Relay class allows for control of a relay
Parameters
Name Type Description
io number | string | object Pin identifier or IO Options (See Instantiating a Device)
options object Device configuration options
Name Type Description
type string "NO" (Normally Open) or "NC" (Normally Closed)
Examples

Use a Relay

import Relay from "j5e/relay";
			
			const relay = await new Relay(12);
Details

Members


<readonly> value :number

Description
A numerical value representing the relay state
Details
number

<readonly> isClosed :boolean

Description
True if the relay is closed
Details
boolean

<readonly> type :string

Description
"NC" if the relay is normally closed, "NO" if the relay is normally open
Details
string

Methods


configure( options ) → {Relay}

Description
Configure a Relay
Parameters
Name Type Description
options object Device configuration options
Name Type Attributes Default Description
type number <optional>
"NO" "NC" if a relay is normally closed, "NO" if it is normally open
Returns
The instance on which the method was called
Examples
import Relay from "j5e/relay";
			
			const relay = await new Relay(14);
			relay.configure({
			  type: "NC"
			});
			
			// With type: "NC", relay.open() sets pin 14 high
			relay.open();
Details

close() → {Relay}

Description
Close the relay circuit
Returns
Examples
import Relay from "j5e/relay"
			
			const relay = await new Relay(12);
			
			// Turn it on
			relay.close();
			
			// Wait 5 seeconds and turn it off
			system.setTimeout(function() {
			  relay.open();
			}, 5000);
Details

open() → {Relay}

Description
Open the relay circuit
Returns
Examples
import Relay from "j5e/relay"
			
			const relay = await new Relay(12);
			
			// Turn it on
			relay.close();
			
			// Wait 5 seeconds and turn it off
			system.setTimeout(function() {
			  relay.open();
			}, 5000);
Details

toggle() → {Relay}

Description
Toggle the relay circuit
Returns
Examples
import Relay from "j5e/relay"
			
			const relay = await new Relay(12);
			
			// Turn it on
			relay.toggle();
			
			// Wait 5 seeconds and turn it off
			system.setTimeout(function() {
			  relay.toggle();
			}, 5000);
Details