DigitalInOut

public final class DigitalInOut

The digital pin can be used to output voltages and read input levels. If a pin is initialized as DigitalInOut, you can change its direction to use it as an input or output pin.

  • Initialize a digital pin as input or output pin.

    Declaration

    Swift

    public init(
        _ idName: IdName,
        direction: Direction = .output,
        outputMode: DigitalOut.Mode = .pushPull,
        inputMode: DigitalIn.Mode = .pullUp,
        outputValue: Bool = false
    )

    Parameters

    idName

    REQUIRED The Digital id on the board. See Id for the specific board in MadBoards library for reference.

    direction

    OPTIONAL Whether the pin serves as input or output.

    outputMode

    OPTIONAL The output mode of the pin. .pushPull by default.

    inputMode

    OPTIONAL The input mode. .pullUp by default.

    outputValue

    OPTIONAL The output value after initiation. false by default.

  • Know if the pin is used for input or output.

    Declaration

    Swift

    public func getDirection() -> Direction

    Return Value

    Input or output.

  • Get the current output mode on a specified pin.

    Declaration

    Swift

    public func getOutputMode() -> DigitalOut.Mode

    Return Value

    The current mode: .pushPull or .openDrain.

  • Get the current input mode on a specified pin.

    Declaration

    Swift

    public func getInputMode() -> DigitalIn.Mode

    Return Value

    The current input mode: .pullUp, .pullDown or .pullNone.

  • Set the pin to output digital signal.

    Declaration

    Swift

    public func setToOutput(_ mode: DigitalOut.Mode? = nil, value: Bool? = nil)

    Parameters

    mode

    The output mode: .pushPull or .openDrain. If you don’t set it, it remains the same as the mode after initialization.

    value

    The output value: true or false. If you don’t set it, it remains the same as the value after initialization.

  • Set the pin to read digital input.

    Declaration

    Swift

    public func setToInput(_ mode: DigitalIn.Mode? = nil)

    Parameters

    mode

    The input mode: .pullUp, .pullDown or .pullNone. If you don’t set it, it remains the same as the mode after initialization.

  • Set the output value of the specific pin: true for high voltage and false for low voltage.

    Declaration

    Swift

    @inline(__always)
    public func write(_ value: Bool)

    Parameters

    value

    The output value: true or false.

  • Set the output value to true.

    Declaration

    Swift

    @inline(__always)
    public func high()
  • Set the output value to false.

    Declaration

    Swift

    @inline(__always)
    public func low()
  • Read the value from the pin.

    Declaration

    Swift

    @inline(__always)
    public func read() -> Bool

    Return Value

    true or false of the logic value.

  • It decides the functionalities of the specified digital pin. It can serve as input or output.

    See more

    Declaration

    Swift

    public enum Direction