from machine import Pin, SPI
import time
time.sleep(0.1) # Espera a que el USB esté preparado
spi0 = SPI(0, 10000000, sck=Pin(2), mosi=Pin(3), miso=Pin(0))
botonVelocidad = Pin(14, Pin.IN, Pin.PULL_DOWN)
botonBrillo = Pin(15, Pin.IN, Pin.PULL_DOWN)
ss = Pin(1, Pin.OUT)
ss.value(1)
def Send(Dir, valor):
buf = [Dir, valor]
ss.value(0)
spi0.write(bytearray(buf))
ss.value(1)
# Configuración inicial de la matriz de LEDs
Send(0x09, 0) # Sin decodificador
Send(0x0A, 8) # Intensidad inicia en 8 (Maximo es 15)
Send(0x0B, 7) # 8 renglones
Send(0x0C, 1) # inicia encendido
cuadro1 = [0x00, 0x7e, 0x60, 0x60, 0x7c, 0x60, 0x60, 0x7e]
cuadro2 = [0x00, 0x63, 0x77, 0x7f, 0x6b, 0x63, 0x63, 0x63]
cuadro3 = [0x00, 0x7c, 0x66, 0x66, 0x7c, 0x66, 0x66, 0x7c]
cuadro4 = [0x00, 0x7e, 0x60, 0x60, 0x7c, 0x60, 0x60, 0x7e]
cuadro5 = [0x00, 0x7c, 0x66, 0x66, 0x7c, 0x66, 0x66, 0x7c]
cuadro6 = [0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c]
cuadro7 = [0x00, 0x7c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7c]
cuadro8 = [0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3c]
cuadro9 = [0x00, 0x3c, 0x66, 0x60, 0x3c, 0x06, 0x66, 0x3c]
velocidades = (250, 200, 150, 100, 50)
velocidad = 2
brillo = 9
retardo = 300
ult_press = {
"velocidad" : 0,
"brillo": 0
}
def Paint(Datos):
for i in range(8):
Send(i+1, Datos[i])
def funVelocidad(botonVelocidad):
global velocidad
t_actual = time.ticks_ms()
if time.ticks_diff(t_actual, ult_press['velocidad']) > retardo:
if velocidad == 4:
velocidad = 0
else:
velocidad += 1
print(velocidad)
ult_press['velocidad'] = t_actual
def funBrillo(botonBrillo):
global brillo
t_actual = time.ticks_ms()
if time.ticks_diff(t_actual, ult_press['brillo']) > retardo:
if brillo >= 15:
brillo = 0
else:
brillo += 3
print(brillo)
Send(0x0A, brillo)
ult_press["brillo"] = t_actual
letras = {
'E': [0x7E, 0x06, 0x06, 0x3E, 0x06, 0x06, 0x7E, 0x00],
'M': [0xC6, 0xEE, 0xFE, 0xD6, 0xC6, 0xC6, 0xC6, 0x00],
'B': [0x3E, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3E, 0x00],
'I': [0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00],
'D': [0x3E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3E, 0x00],
'O': [0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00],
'S': [0x3C, 0x66, 0x06, 0x3C, 0x60, 0x66, 0x3C, 0x00],
' ': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
}
texto = "EMBEBIDOS "
ancho_total = len(texto) * 8 # Ancho en píxeles del texto completo
frame = bytearray(8) # Buffer para la columna actual
def scroll_texto():
for desplazamiento in range(ancho_total):
for col in range(8):
idx_pixel = desplazamiento + col
letra_idx = idx_pixel // 8
columna_letra = idx_pixel % 8
if letra_idx < len(texto):
letra = texto[letra_idx]
frame[col] = letras.get(letra, letras[' '])[columna_letra]
else:
frame[col] = 0x00
Paint(frame)
time.sleep_ms(velocidades[velocidad])
botonVelocidad.irq(trigger=Pin.IRQ_RISING, handler=funVelocidad)
botonBrillo.irq(trigger=Pin.IRQ_RISING, handler=funBrillo)
while True:
scroll_texto()