from machine import Pin
import time
#Configurar entradas A,B,C y D
A=Pin(21, Pin.IN, Pin.PULL_DOWN)
B=Pin(20, Pin.IN, Pin.PULL_DOWN)
C=Pin(19, Pin.IN, Pin.PULL_DOWN)
D=Pin(18, Pin.IN, Pin.PULL_DOWN)
#Configuración de segmentos del display como salida
a=Pin(12,Pin.OUT)
b=Pin(13,Pin.OUT)
c=Pin(11,Pin.OUT)
d=Pin(10,Pin.OUT)
e=Pin(9,Pin.OUT)
f=Pin(8,Pin.OUT)
g=Pin(7,Pin.OUT)
#Crear los números de iluminación
def nada():
a.value(0)
b.value(0)
c.value(0)
d.value(0)
e.value(0)
f.value(0)
g.value(0)
def cero():
a.value(1)
b.value(1)
c.value(1)
d.value(1)
e.value(1)
f.value(1)
g.value(0)
def uno():
a.value(0)
b.value(1)
c.value(1)
d.value(0)
e.value(0)
f.value(0)
g.value(0)
def dos():
a.value(1)
b.value(1)
c.value(0)
d.value(1)
e.value(1)
f.value(0)
g.value(1)
def tres():
a.value(1)
b.value(1)
c.value(1)
d.value(1)
e.value(0)
f.value(0)
g.value(1)
def cuatro():
a.value(0)
b.value(1)
c.value(1)
d.value(0)
e.value(0)
f.value(1)
g.value(1)
def cinco():
a.value(1)
b.value(0)
c.value(1)
d.value(1)
e.value(0)
f.value(1)
g.value(1)
def seis():
a.value(1)
b.value(0)
c.value(1)
d.value(1)
e.value(1)
f.value(1)
g.value(1)
def siete():
a.value(1)
b.value(1)
c.value(1)
d.value(0)
e.value(0)
f.value(0)
g.value(0)
def ocho():
a.value(1)
b.value(1)
c.value(1)
d.value(1)
e.value(1)
f.value(1)
g.value(1)
def nueve():
a.value(1)
b.value(1)
c.value(1)
d.value(1)
e.value(0)
f.value(1)
g.value(1)
#Accionar sistema BCD
while True:
A_valor=A.value()
B_valor=B.value()
C_valor=C.value()
D_valor=D.value()
if (A_valor==0) and (B_valor==0) and (C_valor==0) and (D_valor==0):
cero()
time.sleep(1)
if (A_valor==0) and (B_valor==0) and (C_valor==0) and (D_valor==1):
uno()
time.sleep(1)
if (A_valor==0) and (B_valor==0) and (C_valor==1) and (D_valor==0):
dos()
time.sleep(1)
if (A_valor==0) and (B_valor==0) and (C_valor==1) and (D_valor==1):
tres()
time.sleep(1)
if (A_valor==0) and (B_valor==1) and (C_valor==0) and (D_valor==0):
cuatro()
time.sleep(1)
if (A_valor==0) and (B_valor==1) and (C_valor==0) and (D_valor==1):
cinco()
time.sleep(1)
if (A_valor==0) and (B_valor==1) and (C_valor==1) and (D_valor==0):
seis()
time.sleep(1)
if (A_valor==0) and (B_valor==1) and (C_valor==1) and (D_valor==1):
siete()
time.sleep(1)
if (A_valor==1) and (B_valor==0) and (C_valor==0) and (D_valor==0):
ocho()
time.sleep(1)
if (A_valor==1) and (B_valor==0) and (C_valor==0) and (D_valor==1):
nueve()
time.sleep(1)
else:
nada()
time.sleep(1)