from machine import Pin, SPI
import framebuf
import time
time.sleep(0.1)
# Variables
NOMBRE="LEANDRO"
class MAX7219:
def __init__(self, width, height, spi, cs):
self.spi = spi
self.cs = cs
self.width = width
self.height = height
self.buffer = bytearray(width * height // 8)
self.fb = framebuf.FrameBuffer(self.buffer, width, height, framebuf.MONO_HLSB)
self.cs.init(Pin.OUT, value=1)
self.write_cmd(0x09, 0x00)
self.write_cmd(0x0B, 0x07)
self.write_cmd(0x0A, 0x03)
self.write_cmd(0x0C, 0x01)
self.write_cmd(0x0F, 0x00)
self.fill(0)
self.show()
def write_cmd(self, cmd, data):
self.cs.value(0)
self.spi.write(bytearray([cmd, data]))
self.cs.value(1)
def fill(self, val):
self.fb.fill(val)
def text(self, string, x, y):
self.fb.text(string, x, y, 1)
def show(self):
for row in range(8):
self.cs.value(0)
self.spi.write(bytearray([row + 1, self.buffer[row]]))
self.cs.value(1)
spi=SPI(0, baudrate=10000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(19))
cs=Pin(17, Pin.OUT)
display=MAX7219(8, 8, spi, cs)
ancho_texto=len(NOMBRE) * 8
while True:
for x in range(8, -ancho_texto, -1):
display.fill(0)
display.text(NOMBRE, x, 0)
display.show()
time.sleep(0.1)