from machine import Pin
from agnostic import board as boardId
-from mcp import Enum
+from mcp import Enum,ContextManaged
class DriveMode(Enum):
#Pull.NONE = Pull()
-class DigitalInOut(object):
+class DigitalInOut(ContextManaged):
_pin = None
def __init__(self, pin):
def deinit(self):
del self._pin
- def __enter__(self):
- return self
-
- def __exit__(self, exc_type, exc_value, traceback):
- self.deinit()
-
@property
def direction(self):
return self.__direction
@property
def value(self):
- return self._pin.value()
+ return self._pin.value() is 1
@value.setter
def value(self, val):
if self.direction is Direction.OUTPUT:
- self._pin.value(val)
+ self._pin.value(1 if val else 0)
else:
raise AttributeError("Not an output")