from machine import SoftSPI, Pin, Timer, sleep
from micropython import const
from max7219 import Matrix8x8
import dht
# Define los pines de los botones y los pines de salida
boton_pin = Pin(12, Pin.IN)
boton2_pin = Pin(14, Pin.IN)
red_pin = Pin(4)
green_pin = Pin(16)
blue_pin = Pin(17)
# Configura el sensor DHT22
sensor = dht.DHT22(Pin(15))
# Configura los pines para el display MAX7219
max_clk = const(26)
max_cs = const(25)
max_din = const(33)
spi = SoftSPI(sck=max_clk, mosi=max_din, miso=14)
display = Matrix8x8(spi, Pin(max_cs), 8)
# Función para la acción del botón rojo (Función 1 - HAHUETE)
def funcion_vidreo():
# Lectura del sensor DHT22
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
# Formato de los valores del sensor
temp_str = "{:.1f}C".format(temp)
hum_str = "{:.1f}%".format(hum)
display.fill(0)
display.scroll("EL VIDREO ESTA A: " + temp_str, delay=15) # Scroll del mensaje con la temperatura
display.show()
# Muestra los valores del sensor en la matriz de LED
print("Temperatura:", temp_str)
print("Humedad:", hum_str)
if temp > 60:
red_pin.on()
green_pin.off()
blue_pin.off()
# Función para la acción del botón verde (Función 2 - VIDREO)
def funcion_hahuete():
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
# Formato de los valores del sensor
temp_str = "{:.1f}C".format(temp)
hum_str = "{:.1f}%".format(hum)
# Muestra los valores del sensor en la matriz de LED
display.fill(0)
display.scroll("EL HAHUETE ESTA A: " + temp_str, delay=15) # Scroll del mensaje con la temperatura
display.show()
print("Temperatura:", temp_str)
print("Humedad:", hum_str)
# Tomar la temperatura cada 15 segundos
while True:
# Verifica si se ha presionado el botón rojo
if not boton_pin.value():
while True:
funcion_hahuete() # Llama a la función correspondiente al botón rojo
# Espera 15 segundos antes de tomar la siguiente temperatura
sleep(15)
# Verifica si se ha presionado el botón verde
elif not boton2_pin.value():
while True:
funcion_vidreo() # Llama a la función correspondiente al botón verde
# Espera 15 segundos antes de tomar la siguiente temperatura
sleep(15)