We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6ec58b6 commit 7ac2cf6Copy full SHA for 7ac2cf6
machine/machine/__init__.py
@@ -1,4 +1,5 @@
1
from .timer import *
2
+from .pin import *
3
4
def unique_id():
5
return b"upy-non-unique"
machine/machine/pin.py
@@ -0,0 +1,26 @@
+import umachine
+
+class Pin(umachine.PinBase):
+ IN = "in"
6
+ OUT = "out"
7
8
+ def __init__(self, no, dir=IN):
9
+ pref = "/sys/class/gpio/gpio{}/".format(no)
10
+ dirf = pref + "direction"
11
+ try:
12
+ f = open(dirf, "w")
13
+ except OSError:
14
+ with open("/sys/class/gpio/export", "w") as f:
15
+ f.write(str(no))
16
17
+ f.write(dir)
18
+ self.f = open(pref + "value", "rw")
19
20
+ def value(self, v=None):
21
+ if v is None:
22
+ return self.f.read(1) == "1"
23
+ self.f.write(str(v))
24
25
+ def deinit(self):
26
+ self.f.close()
0 commit comments