from machine import Pin
import utime
PORT= [15, 14, 13, 12, 11, 10, 9, 8]
DIR= ["0","0","0","0","0","0","0","0"]
# port connections
# port directons
L = [0]*8
#This function configures the port pins as outputs ("0") or
# as inputs ("I")
def Configure_Port():
for i in range(0, 8):
if DIR[i] == "0":
L[i]= Pin(PORT[i], Pin.OUT)
else:
L[i]= Pin(PORT[i], Pin.IN)
return
#This function sends 8-bit data (0 to 2555) to the PORT
def Port_Output(x):
b = bin(x)
b = b.replace("0b", "")
diff = 8 - len(b)
for i in range (0, diff):
b = "0" + b
for i in range (0, 8):
if b[i] == "1":
L[i].value(1)
else:
L[i].value(0)
return
# Configure PORT to all outputs
Configure_Port()
# Main program loop. Count up in binary every second #
cnt = 0
while True:
Port_Output(cnt)
utime.sleep(1)
cnt=cnt + 1
if cnt > 255:
cnt = 0