init(_:mode:value:)
Initializes a DigitalOut to a specific pin.
init(_ idName: Id, mode: Mode = .pushPull, value: Bool = false)
Parameters
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)