from machine import Pin
import utime
PORT = [8, 7, 6, 5, 4, 3, 2, 1]
DIR = ["0", "0", "0", "0", "0", "0", "0", "0"]
L = [Pin(p, Pin.OUT) if d == "0" else Pin(p, Pin.IN) for p, d in zip(PORT, DIR)]
def port_output(x):
binary_rep = bin(x)[2:]
binary_rep = '0' * (8 - len(binary_rep)) + binary_rep
for pin, bit in zip(L, binary_rep):
pin.value(int(bit))
cnt = 0
while True:
port_output(cnt)
utime.sleep(1)
cnt = (cnt + 1) % 256