Skip to content

Commit dd28310

Browse files
committed
feature/unit/op.90 & op.180: Infrared photoelectric switch
1 parent 8f7771f commit dd28310

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

m5stack/libs/unit/op.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from machine import Pin
2+
3+
SWITCH = 1
4+
COUNTER = 2
5+
6+
class OPUnit:
7+
8+
def __init__(self, port, type=SWITCH):
9+
self.count_value = 0
10+
self.pin = Pin(port[0], Pin.IN, Pin.PULL_UP)
11+
if type != SWITCH:
12+
self.pin.irq(handler=self._cb_irq, trigger=Pin.IRQ_RISING)
13+
14+
@property
15+
def get_value(self):
16+
return self.pin.value()
17+
18+
def _cb_irq(self, arg):
19+
self.count_value += 1
20+
21+
def count_reset(self):
22+
self.count_value = 0

0 commit comments

Comments
 (0)