init(_:direction:outputMode:inputMode:outputValue:)

Initializes a digital pin as input or output pin.

DigitalInOut.swift:122
init(_ idName: Id, direction: Direction = .output, outputMode: DigitalOut.Mode = .pushPull, inputMode: DigitalIn.Mode = .pullUp, outputValue: Bool = false)

Parameters

idName

REQUIRED Name/label for a physical pin which is associated with the GPIO peripheral. See Id for the board in MadBoards library for reference.

direction

OPTIONAL The pin serves as input or output, output by default.

outputMode

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

inputMode

OPTIONAL The input mode which defines the pull-up/pull-down resistor, .pullUp by default.

outputValue

OPTIONAL The pin output high or low after initialization, false by default.

The statement below shows how to initialize a pin as digital output at first, as the default setting for a pin is output.

 let pin = DigitalInOut(Id.D0)

If you want an input instead, you can define the direction:

 let pin = DigitalInOut(Id.D0, direction: input)