Skip to content

Allow keyword arguments for digital pin setup #5124

@Andon-A

Description

@Andon-A

As it sits right now, I can set up nearly any type of pin input and output in one line. I can, for example, use:

led=pwmio.PWMOut(board.D13, frequency=5000, duty_cycle = 32767)

And this will start a PWM output that, on most boards, will turn the on-board LED on at half power. Similarly, AnalogIn and AnalogOut don't require any setup at all.

DigitalInOut, on the other hand, requires this, to largely accomplish the same thing:

led = digitalio.DigitalInOut(board.D13)
led.switch_to_output(True)
led.value = True

It would be nice if we could do something like this:

led = digitalio.DigitalInOut(board.D13, value=True)

Or, if you're doing an input:

led = digitalio.DigitalInOut(board.D13, pull=digitalio.Pull.UP )

It would definitely be nice to be able to start every pin in a single line, and importing another library just to do that seems a little excessive.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions