new <async> Button( io )

Description
The Button class allows for control of digital buttons
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 button to control an LED

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

Members


<readonly> isClosed :boolean

Description
True if the button is being pressed
Details
boolean

<readonly> isOpen :boolean

Description
True if the button is not being pressed
Details
boolean

<readonly> downValue :number

Description
Get the raw downValue (depends on type and io input mode)
Details
number

<readonly> upValue :number

Description
Get the raw upValue (depends on type and io input mode)
Details
number

holdtime :number

Description
The length of time a button must be held before firing a hold event (in ms)
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.

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

Description
Configure a button
Parameters
Name Type Description
options object Device configuration options
Name Type Attributes Default Description
holdtime number <optional>
500 The amount of time a button must be held down before emitting an hold event
debounce number <optional>
7 The amount of time in milliseconds to delay button events firing. Cleans up "noisy" state changes
type string <optional>
"NO" The type of button, "NO" for normally open, "NC" for normally closed
Returns
The instance on which the method was called
Examples
import Button from "j5e/button";
			import LED from "j5e/led";
			
			const button = await new Button(14);
			button.configure({
			  debounce: 20
			});
			
			button.on("open", function() {
			 led.off();
			});
			
			button.on("close", function() {
			 led.on();
			});
Details