#-----------------------------------------------------------------
# CONTADOR
# Creada por
'''Victoria De Abreu Pires
Mariela Duran Andrade
Fernanda Zamora Toral'''
#-----------------------------------------------------------------
#---[LIBRERÍAS EMPLEADAS]---
import max7219 # Importa la librería max7219 para manejar la matriz de LED
from machine import Pin, SPI # Importa las clases Pin y SPI del módulo machine
import time # Importa el módulo time para manejar el tiempo
#---[AJUSTES]---
spi = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(4), mosi=Pin(2)) # Configuración del bus SPI
ss = Pin(5, Pin.OUT) # Configuración del pin para seleccionar el dispositivo (SS)
display = max7219.Matrix8x8(spi, ss, 4) # Inicializa la matriz de LED con la configuración SPI y SS
i = 0 # Inicializa el contador en 0
#---[DEFINICIÓN DE BOTONES]---
boton_descendente = Pin(34, Pin.IN, Pin.PULL_UP) # Botón para contar descendente
boton_ascendente = Pin(35, Pin.IN, Pin.PULL_UP) # Botón para contar ascendente
boton_parar = Pin(32, Pin.IN, Pin.PULL_UP) # Botón para parar el contador
boton_hola = Pin(33, Pin.IN, Pin.PULL_UP) # Botón para mostrar mensaje "hola"
#---[CICLO PRINCIPAL]---
while True:
if not boton_parar.value(): # Si se presiona el botón para parar el contador
break # Sale del ciclo
if not boton_descendente.value(): # Si se presiona el botón para contar descendente
i -= 1 # Decrementa el contador
elif not boton_ascendente.value(): # Si se presiona el botón para contar ascendente
i += 1 # Incrementa el contador
if not boton_hola.value(): # Si se presiona el botón para mostrar mensaje "hola"
display.text("Hola", 0, 0, 1) # Muestra el mensaje en la matriz de LED
display.show()
time.sleep(2) # Espera 2 segundos antes de borrar el mensaje
display.text("Hola", 0, 0, 0) # Borra el mensaje de la matriz de LED
display.show()
z = str(i) # Convierte el contador a string para mostrarlo en la matriz de LED
display.text(z, 0, 0, 1) # Muestra el contador en la matriz de LED
time.sleep_ms(1) # Espera 1 milisegundo
display.show() # Muestra la matriz de LED con el contador
display.text(z, 0, 0, 0) # Borra el contador de la matriz de LED
time.sleep_ms(1) # Espera 1 milisegundo
display.show() # Muestra la matriz de LED vacía