Module: j5e/relay
Description
A module for controlling an electrically operated switch. Relays are often used to control high voltage devices such as motors, motors, and even motors. These higher voltages can be dangerous, so excercise caution when using this module.
A relay is an electrically operated switch. It consists of a set of input terminals for a single or multiple control signals, and a set of operating contact terminals. The switch may have any number of contacts in multiple contact forms, such as make contacts, break contacts, or combinations thereof.Read more on Wikipedia
Requires
Class: Relay
The Relay class allows for control of a relay
Constructor
new Relay(io, options, options.type)
Parameters
(required)
Description:
Pin identifier or IO Options (See instantiation)
(required)
Description:
Device configuration options
(required)
Description:
"NO" (Normally Open) or "NC" (Normally Closed)
Example
// Use a Relay
import Relay from "j5e/relay";
const relay = await new Relay(12);
Properties
(read only)
(read only)
(read only)
Methods
Relay.configure
Configure a Relay
relay.configure(options);
Returns: The instance on which the method was called
Parameters
(required)
Description:
Device configuration options
Description:
"NC" if a relay is normally closed, "NO" if it is normally open
Default: "NO"
Example
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();
Relay.close
Close the relay circuit
relay.close();
Returns:
Example
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);
Relay.open
Open the relay circuit
relay.open();
Returns:
Example
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);
Relay.toggle
Toggle the relay circuit
relay.toggle();
Returns:
Example
import Relay from "j5e/relay"
import {timer} from "j5e/fn";
const relay = await new Relay(12);
// Turn it on
relay.toggle();
// Wait 5 seeconds and turn it off
timer.setTimeout(function() {
relay.toggle();
}, 5000);