init(_:mode:value:)

Initializes a DigitalOut to a specific pin.

DigitalOut.swift:161
init(_ idName: Id, mode: Mode = .pushPull, value: 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.

mode

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

value

OPTIONAL The output value after initialization, false by default.

The id of the pin is required to initialize a digital out pin. It can be any pin with that function, D0, D1, D2… The prefix D means Digital. If you connect a device to the pin D10, you should initialize the pin using Id.D10.

All ids for different boards are in the MadBoards library. Take pin 0 for example, the pin works as a DigitalOut pin after initialization:

// The simplest way to initialize a pin, with other parameters set to default.
let outputPin0 = DigitalOut(Id.D0)

There are two more optional parameters to configure the pin.

// Initialize the pin D1 with the output mode openDrain.
let outputPin1 = DigitalOut(Id.D1, mode: .openDrain)

// Initialize the pin D2 with a High voltage output.
let outputPin2 = DigitalOut(Id.D2, value: true)

// Initialize the pin D3 with the openDrain mode and a High voltage output.
let outputPin3 = DigitalOut(Id.D3, mode: .openDrain, value: true)