new <async> Switch( io )

Description
The Switch class allows for control of digital switches
Parameters
Name Type Description
io number | string | object Pin identifier or IO Options (See Instantiating a Device)
Name Type Attributes Default Description
mode number | string <optional>
Input Device configuration options. If a number, a valid value based on the Provider's constants. If a string, one of "Input", "InputPullUp", or "InputPullDown"
Examples

Use a switch to control an LED

import Switch from "j5e/switch";
			import LED from "j5e/led";
			
			const mySwitch = await new Switch(12);
			const led = await new LED(13);
			
			mySwitch.on("open", function() {
			  led.off();
			});
			
			mySwitch.on("close", function() {
			  led.on();
			});
Fires

Members


<readonly> isClosed

Description
True if the switch is closed (current is flowing)
Returns
Details

<readonly> isOpen

Description
True if the switch is open (current is not flowing)
Returns
Details

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.

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.