from machine import Pin
import time
btnInc = Pin(8,Pin.IN,Pin.PULL_UP)
btnDec = Pin(10,Pin.IN,Pin.PULL_UP)
a = Pin(16,Pin.OUT)
b = Pin(17,Pin.OUT)
c = Pin(18,Pin.OUT)
d = Pin(19,Pin.OUT)
e = Pin(20,Pin.OUT)
f = Pin(21,Pin.OUT)
g = Pin(22,Pin.OUT)
a2 = Pin(1,Pin.OUT)
b2 = Pin(2,Pin.OUT)
c2 = Pin(3,Pin.OUT)
d2 = Pin(4,Pin.OUT)
e2 = Pin(5,Pin.OUT)
f2 = Pin(6,Pin.OUT)
g2 = Pin(7,Pin.OUT)
segmento2 = [a2,b2,c2,d2,e2,f2,g2]
segmento = [a,b,c,d,e,f,g]
tabla = [0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x83,0xf8,0x80,0x98]
contador=0
contador2=0
def bit_test(x,n):
if x & (1 << n) != 0:
return 1
else:
return 0
#Iniciamos el display en 0
while True:
#Parte del incremento
if btnInc.value() == 0:
contador2 +=1
if contador2>9:
contador2=0
contador+=1
if contador>9:
contador=0
#Parte del decremento
if btnDec.value() == 0:
contador2 -=1
if contador2<0:
contador2=9
contador-=1
if contador<0:
contador=9
for i in range (7):
segmento[i].value(bit_test(tabla[contador],i))
for i in range (7):
segmento2[i].value(bit_test(tabla[contador2],i))
time.sleep(.300)