import time
import machine
PL_PIN = machine.Pin(4, machine.Pin.OUT, value=1)
CP_PIN = machine.Pin(3, machine.Pin.OUT, value=0)
Q_PIN = machine.Pin(2, machine.Pin.IN)
def read_shift_register(pl,cp,q):
"""Reads 8 bits from the 74HC165 shift register."""
# Latch parallel inputs into shift register
pl.value(0)
time.sleep_us(5)
pl.value(1)
time.sleep_us(5)
value = 0
print("##############################")
for i in range(8):
print("Dip: {}, Value: {}".format(i,q.value()))
value = (value << 1) | q.value()
cp.value(1)
time.sleep_us(5)
cp.value(0)
time.sleep_us(5)
return value
time.sleep(0.1) # Wait for USB to become ready
while True:
#print("Shift Register Data: {}".format(read_shift_register(pl=PL_PIN,cp=CP_PIN,q=Q_PIN)))
read_shift_register(pl=PL_PIN,cp=CP_PIN,q=Q_PIN)
time.sleep_ms(50)