micropython/tests/extmod/machine_signal.py
Damien George 61616e84ce extmod/machine_signal: Rename "inverted" arg to "invert", it's shorter.
A shorter name takes less code size, less room in scripts and is faster to
type at the REPL.

Tests and HW-API examples are updated to reflect the change.
2017-04-15 21:01:47 +03:00

41 lines
702 B
Python

# test machine.Signal class
try:
import umachine as machine
except ImportError:
import machine
try:
machine.PinBase
machine.Signal
except AttributeError:
print("SKIP")
import sys
sys.exit()
class Pin(machine.PinBase):
def __init__(self):
self.v = 0
def value(self, v=None):
if v is None:
return self.v
else:
self.v = int(v)
# test non-inverted
p = Pin()
s = machine.Signal(p)
s.value(0)
print(p.value(), s.value())
s.value(1)
print(p.value(), s.value())
# test inverted, and using on/off methods
p = Pin()
s = machine.Signal(p, invert=True)
s.off()
print(p.value(), s.value())
s.on()
print(p.value(), s.value())