OutputDevice

OutputDevice

new OutputDevice(pin, active_highopt, initial_valueopt)

Source:
Represents a generic GPIO output device. Provides facilities common to GPIO output devices an on method to switch the device on, a corresponding off method, and a toggle method.
Parameters:
Name Type Attributes Description
pin int | Pin The GPIO pin (in BCM numbering) or an instance of Pin that the device is connected to.
active_high boolean <optional>
If `true` (the default), the on method will set the GPIO to HIGH. If `false`, the :on method will set the GPIO to LOW (the off method always does the opposite).
initial_value boolean <optional>
If `false` (the default), the device will be off initially. If `undefined`, the device will be left in whatever state the pin is found in when configured for output (warning: this can be on). If `true`, the device will be switched on initially.
Throws:
GPIOPinMissing - When pin is undefined.

Extends

Methods

active_high(valueopt)

Source:
This property can be set after construction; be warned that changing it will invert value (i.e. changing this property doesn't change the device's pin state - it just changes how that state is interpreted).
Parameters:
Name Type Attributes Description
value boolean <optional>
When ``true``, the value property is ``true`` when the device's pin is high. When ``false`` the value property is ``true`` when the device's pin is low (i.e. the value is inverted).

close()

Source:
Inherited From:
Close the device and remove the pin allocation allowing it to be reused.

closed() → {boolean}

Source:
Inherited From:
Returns:
- Is ``true`` is no pin is allocated.
Type
boolean

is_active() → {boolean}

Source:
Inherited From:
Returns:
- Is true is the device value is currently set.
Type
boolean

off()

Source:
Turns the device off.

on()

Source:
Turns the device on.

pin() → {undefined|*|int|Pin}

Source:
Inherited From:
Returns:
- The Pin that the device is connected to. This will be ``undefined`` if the device has been closed (see the :meth:`close` method). When dealing with GPIO pins, query ``pin.number`` to discover the GPIO pin (in BCM numbering) that the device is connected to.
Type
undefined | * | int | Pin

toggle()

Source:
Reverse the state of the device. If it's on, turn it off; if it's off, turn it on.

toString() → {string}

Source:
Inherited From:
Returns:
- Description of the device.
Type
string

value(valueopt) → {boolean|float}

Source:
Overrides:
Parameters:
Name Type Attributes Description
value boolean | float <optional>
When supplied the device output is changed to the value.
Returns:
- When value is undefined, the function returns the current value of the device.
Type
boolean | float