Commit f17468e6 authored by Ralf's avatar Ralf
Browse files

testblinker test input pins

parent 11c74940
......@@ -49,16 +49,19 @@ class I2C:
# now we know what to set
self.setPins(pin.addr, byte)
def getPin(self, pin):
def getPins(self, addr):
with self._lock:
if not self._active:
return None
# read the current value
byte = self._bus.read_byte(pin.addr)
# now we need to get the bit
mask = (1 << pin.bit)
return bool(byte & mask)
return self._bus.read_byte(addr)
def getPin(self, pin):
# read the current value
byte = self.getPins(pin.addr)
if byte is None: return None
# now we need to get the bit
mask = (1 << pin.bit)
return bool(byte & mask)
# kate: space-indent off; tab-width 4; indent-width 4;
\ No newline at end of file
#!/usr/bin/python3
from busfahrer import I2C, Pin
import time
b = I2C(1)
b.setPins(0x20, 0xFF)
b.activate()
i = 0
while True:
......@@ -11,5 +13,6 @@ while True:
b.setPin(Pin(0x21, 5), (i//2) % 2 == 0)
b.setPin(Pin(0x21, 6), (i//4) % 2 == 0)
b.setPin(Pin(0x21, 7), (i//8) % 2 == 0)
time.sleep(0.2)
print("{:08b}".format(b.getPins(0x20)))
time.sleep(0.02)
i += 1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment