Skip to content

digitalio.DigitalInOut constructor should accept direction #8534

@rgov

Description

@rgov

It would be nicer to write

pin = digitalio.DigitalOut(pin=board.GP123)

# or this
pin = digitalio.DigitalInOut(pin=board.GP123, direction=digitalio.Direction.OUTPUT)

# than this
pin = digitalio.DigitalInOut(pin=board.GP123)
pin.switch_to_output()

"Explicit is better than implicit." Defaulting to input seems arbitrary and it would be better for code to be explicit about direction. And it makes it a one-liner to define an output pin, which is nice if you're doing many of these.

Note analogio differentiates AnalogIn and AnalogOut which is also very readable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions