import max7219
from machine import Pin, SPI
import time
spi = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(4), mosi=Pin(2))
ss = Pin(5, Pin.OUT)
display = max7219.Matrix8x8(spi, ss, 4)
mantener = Pin(23,Pin.IN,Pin.PULL_UP)
presionar= Pin(22, Pin.IN, Pin.PULL_UP)
presionar2 = Pin(21, Pin.IN, Pin.PULL_UP)
imprimir= Pin(19, Pin.IN, Pin.PULL_UP)
cont = 0
stop = False
while True:
display.text(str(cont), 0, 0, 1)
display.show()
while True:
if mantener.value()==0:
time.sleep(.1)
if mantener.value()==1:
break
while True:
if presionar.value()==0:
if stop == False:
stop = True
while stop == True:
time.sleep(.1)
if presionar2.value() == 0:
stop=False
break
break
if presionar.value()==1:
break
while True:
if imprimir.value() == 0:
while True:
display.text('STOP', 0, 0, 1)
display.show()
if presionar2.value() == 0:
break
break
if imprimir.value() == 1:
break
time.sleep(.1)
display.fill(0) # Limpia la pantalla
cont += 1