Description
@ZodiusInfuser asked in #4228 whether DigitalInOut
has functionality to invert the sense of .value
, so that True
represents a low signal level , and False
represents high. The motivation is that Pimoroni has boards where the RGB LEDs are common anode. But this functionality could also be used for buttons that ground when on, etc.
MicroPython has a Signal
class that wraps Pin
and has an optional invert
argument: classmachine.Signal(pin_obj, invert=False)
.
DigitalInOut
could take an optional invert
argument, which would invert the sense of .value
. That might be all that is necessary.
We could also leave .value
alone, and add, say, an .on
property that depends on invert
. Or we could add a .level
property that always corresponds to high and low, and let .value
be influenced by invert
. But these extra properties may not be necessary.
One still needs to know whether a pin is active-high or active-low. Right now the board-specific pin names do not indicate that. We could start adding _INV
or some other indicator to their names to make that clearer.